Count in an hour

Hi,
I have a counter “orders_created_total” scraped by prometheus every 30seconds.

I want to visualise “Orders created every hour” in grafana

Example:
1:00 - orders_created_total =5
2:00 - orders_created_total =10
3:00 - orders_created_total =25

in graph with bar:
2:00 → 5
3:00 → 15

How can I achieve this?

Things I tried, but not working:
delta(orders_created_count_total[1h])
sum(increase(orders_created_count_total[1h]))
max_over_time(orders_created_count_total[1h]) - min_over_time(orders_created_count_total[1h])

1 Like

I’m having the same issue. sum(increase(orders_created_count_total[1h])) is also the function that I’m using, but it either returns 0 or a very low number.
Say my counter has had gone from 1000 to 1600 in one hour, I expect the above to returns 600, but get ~5.
The counter is created by the following Golang code:

prometheus.NewCounterVec(
		prometheus.CounterOpts{
			Namespace:   namespace,
			Subsystem:   "",
			Name:        "state_total",
			Help:        "Count of state transitions",
			ConstLabels: labels,
		}, []string{"from", "to", "userId"})

And increments are done using
m.stateCount.WithLabelValues(string(from), string(to), userId).Inc()

The attached photo has sum(increase(...[24h])) and sum(...), where the number shown is Last* and the duration of the graph is 24 hours. It is clear, that the total changes in the right column is a lot higher than 13.1.

@Jgfrausing and @prabhu I believe to achieve what you want that query will work if you add Min step 3600

And with Min step at 3600 you do not need sum both sum(increase(orders_created_count_total[1h])) and increase(orders_created_count_total[1h]) give the same result.

I’ve created an issue in Prometheus. Lets see if they agree, there is an error.

@prabhu
I found the issue. :confetti_ball:
Apparently, the user id breaks the aggregation. I removed it from the metric, and everything works fine now… I think, you should look for labels with many distinct values and remove those labels.

They have a caution block, that describes just this. :confused:
Metric and label naming | Prometheus.