Bukharov Sergey
Bukharov Sergey

Reputation: 10185

How to measure throughput with dynamic interval in Grafana

We are measuring throughput using Grafana and Influx. Of course, we would like to measure throughput in terms how many requests, approximately, happens every single second (rps). The typical request is:

SELECT sum("count") / 10 FROM "http_requests" GROUP BY time(10s)

But we are loosing possibility to use astonishing dynamic $__interval that very useful when graph scope is large, like a day of week. When we are changing interval we should change divider into SELECT expression.

SELECT sum("count") / $__interval FROM "http_requests" GROUP BY time($__interval) But this approach does not work, because of empty result returns.

How to create request using dynamic $__interval for throughput measuring?

Upvotes: 0

Views: 2790

Answers (1)

The reason you get no results is that $__interval is not a number but a string such as 10s, 1m, etc. that is understood by influxdb as a time range. So it is not possible to use it the way you are trying.

However, what you want to calculate is the mean which is available as a function in InfluxQL. The way to get the behavior that you want is with something like this.

SELECT mean("count") FROM "http_requests" GROUP BY time($__interval)

EDIT: On a second thought that is not quite what you want. You'd probably need to use derivative. I'll come back to you on that one later.

Edit2: Do you think this answers the question that you have Calculating request per second using InfluxDB on Grafana

Edit3: Third edit's a charm. We use your starting query and wrap it in another one as such: SELECT sum("rps") from (SELECT sum("count") / 10 as rps FROM "http_requests" GROUP BY time(10s)) GROUP BY time($__interval)

Upvotes: 4

Related Questions