1

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

indolentdeveloper
  • 1,253
  • 1
  • 11
  • 15

1 Answers1

3

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]))).

Alin Sînpălean
  • 8,774
  • 1
  • 25
  • 29