sum(increase(http_requests_total[$__range]))
worked for me. $__range is grafana variable which reflects time range selected in top right of grafana.
It is highly recommended to use increase to automatically adjust counter for resets.
Increase results in fractional values due to extrapollation at boundaries as well. Rounding functions with the query also worked for me.
round(sum(increase(http_requests_total[$__range])))
or
Since you are using grafana you can set decimals to 0 in standard options. (in grafana 9.1.8 this is not working, its bug). So I have set this in panel json as below.
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"value": null,
"color": "green"
},
{
"value": 80,
"color": "red"
}
]
},
"color": {
"mode": "thresholds"
},
"decimals": 0,
"unit": "none"
},
"overrides": []
}
Note: These queries are tried with grafana stat panel. (grafana version 9.1.8)
increase()
function on a time series with integer values. It may also miss some values on slowly increasing time series. Both issues are documented at github.com/prometheus/prometheus/issues/3746 . If you need accurate integer values fromincrease()
function, then take a look at MetricsQL. – Mcginnis