Vaidas Sirtautas
Vaidas Sirtautas

Reputation: 113

Grafana & Prometheus: Count for Today

I have a constantly increasing counter e.g.

my_counter{uid="1", srv="a"}
my_counter{uid="1", srv="b"}
my_counter{uid="2", srv="a"}
my_counter{uid="2", srv="b"}
...

and I'd like to build a Grafana dashboard to show what is the diff of the value today (since midnight to now).

This is the query that I came up with sum(increase(my_counter{}[$__range])) by (uid) and the $__range is selected as "Today so far" in Grafana.

I would imagine that the "start" value should not matter in this case and the graph should always start from zero since it should be calculating delta's from midnight to now, but that does not seem to be the case.

What would be the best approach to figuring out what is wrong with the query or maybe I am completely misunderstanding how increase function works in this case?

Thanks in advance.

EDIT (2020-06-24 16:04 CEST):

I think I am misunderstanding how this works and my question is a bit unclear. To get the count for today I would like to see the value(my_counter at now) - value(my_counter at 00:00(CEST))

Is that even doable in Grafana?

Upvotes: 4

Views: 2973

Answers (1)

trallnag
trallnag

Reputation: 2376

$__range always delivers - as you have already pointed out - the selected time range. For example 100 minutes. This is what gets passed on to Prometheus in the range selector.

Lets assume a step of 10. The query tells Prometheus to get the rate per second averaged over $__range from 0 to 10 times $__range. Then averaged over $__range from 10 to 20 times $__range. So you should get something like this

enter image description here

I use $__range only in combination with the instant option in Grafana.

Upvotes: 1

Related Questions