9

I use telegraf plugin nginx to read Nginx's basic status information (ngx_http_stub_status_module)

This is my query

request per second query

raw sql:

SELECT derivative(mean("requests"), 1s) FROM "nginx" WHERE $timeFilter GROUP BY time($interval) fill(null)

This is my data

time            accepts active  handled host    port    reading requests    server      waitingwriting
1464921070000000000 7   1   7   hysm    80  0   17      localhost   0   1
1464921080000000000 8   1   8   hysm    80  0   19      localhost   0   1
1464921090000000000 8   1   8   hysm    80  0   20      localhost   0   1
1464921100000000000 8   1   8   hysm    80  0   21      localhost   0   1

but requestPerSecond is 0.083, what is wrong with my query?

request per second graph

jk2K
  • 4,279
  • 3
  • 37
  • 40
  • What do you expect it to be? My first inclination is that you're taking the average and then taking the derivative of that which should skew things a bit because your average will change in relation to your `group by time($interval)`. – Michael Desa Jun 06 '16 at 17:29
  • Have you tried setting the unit on the derivative to be equal to the `GROUP BY time()` interval? (usually defaults to 10s in Grafana) – Gunnar Jun 07 '16 at 22:44
  • @MichaelDesa, I would like to know whether the result(requestPerSecond) is right – jk2K Jun 08 '16 at 07:31
  • 1
    What does `requests` represent? Is it just a counter? If it is then you'll want to run `derivative(max(requests))` that should give you something more accurate than `mean`. – Michael Desa Jun 08 '16 at 18:14
  • @MichaelDesa, just a counter, thanks – jk2K Jun 09 '16 at 05:54
  • Hey @jk2K , can you please tell me the setup by which you are able to get this nginx info on influxdb. How have you connected your stub_module to influxdb ? – Luv33preet Mar 21 '17 at 09:26

1 Answers1

6

Assuming that you're dealing with a a counter, the query you're going to want is

SELECT derivative(max(requests))
FROM "nginx"
WHERE $timeFilter
GROUP BY time($interval)
Michael Desa
  • 4,607
  • 24
  • 19