Grafana: duplicate Legend and Graph for Rate Query after Pod Restart

Viewed 103

I want to show the rate of logins per hour in a web app. This is the PromQL query I have:

rate(logins_total[1h])*3600

The situation in the database is that there has been a restart of the pod running the webapp and there was one login after the restart.

If I show the last hour, then the graph looks fine. But if I show the last 3 hours, then the legend is duplicated as well as the graph (see screenshots). I do realise that there are now two time series, one for the old pod and another for the new pod. What I would like to show is just one graph and one legend.

So basically the second screenshot should look like the first - is that possible at all?

enter image description here enter image description here

1 Answers

Just wrap the query into sum aggregate function in order to merge multiple series into a single one:

sum(rate(logins_total[1h])*3600)

P.S. It may be more clear to use increase instead of rate multiplied by time range in seconds:

sum(increase(logins_total[1h]))

P.P.S. note that rate and increase in Prometheus may return unexpected results over slow-changing integer counters because of the following issues:

  • extrapolation
  • missing increase between the last raw sample just before the lookbehind window specified in square brackets and the first raw sample in the lookbehind window. See these docs.

Both issues are resolved in VictoriaMetrics - this is Prometheus -like monitoring solution I work on. See MetricsQL docs for details.

Related