indolentdeveloper
indolentdeveloper

Reputation: 1313

How to get total request within a time range as single scalar value in prometheus?

I want to get total number of request in a time interval as scalar values.

I have tried various solution but all give me back a time series vector. I want a single value. Does any one know how to do that.

I have tried. sum(increase(http_request_duration_ms_count[1m]))) or here

Upvotes: 2

Views: 5682

Answers (1)

Alin Sînpălean
Alin Sînpălean

Reputation: 10134

Not sure what you mean by time series vector vs. scalar. Prometheus defines the concepts of

  • instant vector, e.g. up{instance="foo"}: (1, t1), up{instance="bar"}: (0, t1);
  • range vectors, e.g. up{instance="foo"}: [(1, t0), (1, t1)], up{instance="bar"}: [(0, t1), (1, t2)]; and
  • scalar, e.g. 5.

sum(increase(http_request_duration_ms_count[1m])) will always produce an instant vector, i.e. the first of the above, consisting of a single time series with a single sample (as long as there exists at least one http_request_duration_ms_count time series).

If you want to turn that into a scalar (as defined by Prometheus) all you need to do is put a scalar() function call around it, i.e. scalar(sum(increase(http_request_duration_ms_count[1m]))).

Upvotes: 3

Related Questions