Jordi
Jordi

Reputation: 23187

PromQL: counter and rate hint

When I'm trying to build a panel into my grafana dashboard using a counter metric, it's telling me:

Selected metric is a counter. Consider calculating rate of counter by adding rate().

  1. Why it suggest me above hint?
  2. Has any relation with scrape_interval?

I'm using those metrics:

How should I visualize them? I mean, which promQL should I use?

Currently, I'm using them straightforwardly.

Upvotes: 2

Views: 3817

Answers (1)

valyala
valyala

Reputation: 17784

Counter metrics are rarely useful when displayed on the graph. For example, try obtaining any useful information from the graph on the method_timed_seconds_sum metric. That's why it is recommended wrapping these metrics into rate or increase functions:

  • rate(m[d]) returns the average per-second increase rate for counters matching m series selector over the lookbehind window d. For example, rate(method_timed_seconds_count[5m]) returns the average requests per second over the last 5 minites.
  • increase(m[d]) returns the increase of counters matching m over the lookbehind window d. For example, increase(method_timed_seconds_count[1h]) returns the number of requests during the last hour.

Both method_timed_seconds_count and method_timed_seconds_sum counters can be used for calculating the average request duration on an arbitrary lookbehind window. For example, the following query returns the average request duration over the last 5 minutes:

increase(method_timed_seconds_sum[5m])
  /
increase(method_timed_seconds_count[5m])

E.g. this query divides the sum of duration of all the requests during the last 5 minutes by the the number of requests during the last 5 minutes.

Upvotes: 5

Related Questions