This works for me:
sum(increase(http_request_duration_seconds_count{ecs_cluster=~"$ecs_cluster", instance_id=~"$instance_id"}[$__range]))
Activated instant query and set calculation to last not null

Here is the pane JSON:
{
"cacheTimeout": null,
"datasource": "Prometheus",
"description": "",
"fieldConfig": {
"defaults": {
"custom": {},
"unit": " requests",
"decimals": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"mappings": [],
"nullValueMode": "connected"
},
"overrides": []
},
"gridPos": {
"h": 2,
"w": 5,
"x": 0,
"y": 4
},
"id": 4,
"interval": null,
"links": [],
"maxDataPoints": 100,
"options": {
"reduceOptions": {
"values": false,
"calcs": [
"lastNotNull"
],
"fields": ""
},
"orientation": "horizontal",
"textMode": "auto",
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
}
},
"pluginVersion": "7.1.0",
"targets": [
{
"expr": "sum(increase(http_request_duration_seconds_count{ecs_cluster=~\"$ecs_cluster\", instance_id=~\"$instance_id\"}[$__range]))",
"hide": false,
"instant": true,
"interval": "",
"intervalFactor": 1,
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "",
"type": "stat"
}

This works for me:
sum(increase(http_request_duration_seconds_count{ecs_cluster=~"$ecs_cluster", instance_id=~"$instance_id"}[$__range]))
Activated instant query and set calculation to last not null

Here is the pane JSON:
{
"cacheTimeout": null,
"datasource": "Prometheus",
"description": "",
"fieldConfig": {
"defaults": {
"custom": {},
"unit": " requests",
"decimals": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "blue",
"value": null
}
]
},
"mappings": [],
"nullValueMode": "connected"
},
"overrides": []
},
"gridPos": {
"h": 2,
"w": 5,
"x": 0,
"y": 4
},
"id": 4,
"interval": null,
"links": [],
"maxDataPoints": 100,
"options": {
"reduceOptions": {
"values": false,
"calcs": [
"lastNotNull"
],
"fields": ""
},
"orientation": "horizontal",
"textMode": "auto",
"colorMode": "value",
"graphMode": "none",
"justifyMode": "auto",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
}
},
"pluginVersion": "7.1.0",
"targets": [
{
"expr": "sum(increase(http_request_duration_seconds_count{ecs_cluster=~\"$ecs_cluster\", instance_id=~\"$instance_id\"}[$__range]))",
"hide": false,
"instant": true,
"interval": "",
"intervalFactor": 1,
"legendFormat": "",
"refId": "A"
}
],
"timeFrom": null,
"timeShift": null,
"title": "",
"type": "stat"
}

Prometheus may return inaccurate results from increase() function because of the chosen data model - see this issue for details.
If you need accurate results, then the following options exist:
- To use
offset. Try something like the following:sum(http_server_requests_seconds_count - http_server_requests_seconds_count offset $__range). Note that this approach works only if the given metric -http_server_requests_seconds_countwasn't reset to 0 (akacounter reset) on the given time range. - To use
increase()function from MetricsQL. It returns accurate values - see these docs for details.
Graphing slow counters with prometheus and grafana - Stack Overflow
Time Series of counter rates from Prometheus: organize as (a, b) with an additional label z
Need help visualizing a simple counter
How to take the previous counter value and add it to the new one in case it resets to zero on Grafana?
That's a correct way to do it. You can also use increase() which is syntactic sugar for using rate() that way.
Can someone explain how the range selector
This is only used by Prometheus, and indicates what data to work over.
the Step and Resolution settings in grafana influence each other?
This is used on the Grafana side, it affects how many time slices it'll request from Prometheus.
These settings do not directly influence each other. However the resolution should work out to be smaller than the range, or you'll be undersampling and miss information.
The 3600 * sum(rate(signup_total[1h])) can be substituted with sum(increase(signup_total[1h])) . The increase(counter[d]) function returns counter increase on the given lookbehind window d. E.g. increase(signup_total[1h]) returns the number of signups during the last hour.
Note that the returned value from increase(signup_total[1h]) may be fractional even if signup_total contains only integer values. This is because of extrapolation - see this issue for technical details. There are the following solutions for this issue:
- To use offset modifier:
signup_total - (signup_total offset 1h). This query returns correct results ifsignup_totalwasn't reset to zero during the last hour. In this case thesum(signup_total - (signup_total offset 1h))is roughly equivalent tosum(increase(signup_total[1h])), but returns more accurate integer results. - To use VictoriaMetrics. It returns the expected integer results from
increase()out of the box. See this article and this comment for technical details.
Hi Prometheus community,
I’m relatively new to Prometheus, having previously used InfluxDB for metrics. I’m struggling to visualize a simple counter (http_requests_total) in Grafana, and I need some advice. Here’s what I’m trying to achieve:
-
Count graph, NOT rate or percentage: I want the graph to show the number of requests over time. For example, if I select “Last 6 hours,” I want to see how many requests occurred during that time window.
-
Relative values only: I don’t care about the absolute counter value (e.g., "150,000" at some point). Instead, I want the graph to start at 0 for the beginning of the selected time window and show relative increments from there.
-
Smooth increments: I don’t want to see sharp peaks every time the counter increments, like what happens with
increase(). -
Adaptable to any time frame: The visualization should automatically adjust for any selected time range in Grafana.
Here’s an example of what I had with InfluxDB (attached image). It shows the actual peaks and their sizes in absolute numbers over time, which is exactly what I need.
I can’t seem to replicate this with Prometheus. Am I missing something fundamental?
Thanks for your help!
So I have a counter metric, I aggregate it by sum based on two label values. My question is, after the application restarts the counter is going to reset to zero, but on grafana I want to keep the counter persistent, meaning that when the counter becomes zero, I want to take the previous value and add it to the new counter value.
So if counter metric is 5.0, application restarts and now the counter metric is 0, I basically want to take previous value 5 and add it to the current value 0.
Does this make sense? I don't know how to do it.