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"
}

Answer from trallnag on Stack Overflow
Top answer
1 of 2
10

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"
}

2 of 2
0

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_count wasn't reset to 0 (aka counter reset) on the given time range.
  • To use increase() function from MetricsQL. It returns accurate values - see these docs for details.
🌐
Temporal
community.temporal.io › community support
Properly plot counters with Prometheus in Grafana - Community Support - Temporal Community Forum
March 1, 2023 - Hi, I have been trying to figure out how to properly plot some of the following counters to show some breakdown on workflow_type or activity_type: temporal_workflow_completed_total temporal_workflow_failed_total temporal_request_total (for plotting all successful activity) temporal_activit...
Discussions

Graphing slow counters with prometheus and grafana - Stack Overflow
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. ... Sign up to request clarification or add additional context in comments. ... I'm still having a hard time putting everything together. For a counter ... More on stackoverflow.com
🌐 stackoverflow.com
Time Series of counter rates from Prometheus: organize as (a, b) with an additional label z
Using Grafana 11.2.0 Prometheus metrics are counter(s) with labels “a”, “b”, and “z”. “a” and “b” labels separate counter metrics, but label “z” is solely a useful annotation. I would like to (1) colorize the specific series shown by (a, b) but not z, and (2) still show ... More on community.grafana.com
🌐 community.grafana.com
2
0
November 26, 2024
Need help visualizing a simple counter
Your description and your example graph are inconsistent. If you want the start point of the graph to always be zero, you're probably looking for a graph like this: sum( http_requests_total - http_requests_total @ ${__from:date:seconds} ) This uses the Grafana $__from variable and the @ modifier . But your example graph is an increase() graph like this: increase(http_requests_total[$__rate_interval]) More on reddit.com
🌐 r/PrometheusMonitoring
8
0
December 11, 2024
How to take the previous counter value and add it to the new one in case it resets to zero on Grafana?
Typically, you would use rate, which accounts for counters resets. Is there any reason not to use rate? What's the use case, just out of curiosity? More on reddit.com
🌐 r/PrometheusMonitoring
8
2
July 21, 2023
🌐
Prometheus
prometheus.io › docs › concepts › metric_types
Metric types | Prometheus
They are also created regularly by PromQL expressions. For example, the outcome of applying the rate function to a counter histogram is a gauge histogram, in the same way as the outcome of applying the rate function to a counter is a gauge.
Top answer
1 of 2
9

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.

2 of 2
0

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 if signup_total wasn't reset to zero during the last hour. In this case the sum(signup_total - (signup_total offset 1h)) is roughly equivalent to sum(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.
🌐
INNOQ
innoq.com › en › blog › 2019 › 05 › prometheus-counters
Prometheus Counters and how to deal with them – INNOQ
May 20, 2019 - In this article, I want you to join me on my way to understand how Counters in Prometheus work, and how to query them to get the right information. ... I recently had to setup a few monitoring dashboards in Grafana based on a Prometheus data source. I focussed on a couple of already existing counter metrics.
🌐
Grafana
community.grafana.com › time series panel
Time Series of counter rates from Prometheus: organize as (a, b) with an additional label z - Time Series Panel - Grafana Labs Community Forums
November 26, 2024 - Using Grafana 11.2.0 Prometheus metrics are counter(s) with labels “a”, “b”, and “z”. “a” and “b” labels separate counter metrics, but label “z” is solely a useful annotation. I would like to (1) colorize the specific s…
🌐
GitConnected
levelup.gitconnected.com › prometheus-counter-metrics-d6c393d86076
Working With Prometheus Counter Metrics | Level Up Coding
February 28, 2022 - The graphs we’ve seen so far are useful to understand how a counter works, but they are boring. To give more insight into what these graphs would look like in a production environment, I’ve taken a couple of screenshots from our Grafana dashboard at work.
Find elsewhere
🌐
Reddit
reddit.com › r/prometheusmonitoring › need help visualizing a simple counter
r/PrometheusMonitoring on Reddit: Need help visualizing a simple counter
December 11, 2024 -

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:

  1. 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.

  2. 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.

  3. Smooth increments: I don’t want to see sharp peaks every time the counter increments, like what happens with increase().

  4. 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!

🌐
Reddit
reddit.com › r/prometheusmonitoring › how to take the previous counter value and add it to the new one in case it resets to zero on grafana?
r/PrometheusMonitoring on Reddit: How to take the previous counter value and add it to the new one in case it resets to zero on Grafana?
July 21, 2023 -

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.

Top answer
1 of 1
8

Counter 101

why does the short time-range fluctuates when the counter goes only up?

Counter indeed only goes up. But this is of little use on its own - if a value only goes up why do you care about exact value? Today it's 1, tomorrow it's 42, and in a week it's 100500. What we really want is to know how quickly a counter is increasing over time (if it's of value 42 afer the first day, why is it 100500 in just a week and not near 294?).

If you really care about the actual value the Gauge should be used, which also might go down.

increase()

The increase() function in PromQL does exactly what you want to do with counters - it takes the history of metrics over a time frame and calculates how fast value is increasing.

Could a counter be increased by 10 during the first minute, and by 3 during the next minute? Sure, that's why increase graph goes up and down ("fluctuates"). When you set a small range interval like on the 2nd graph it's visible, when you set a large range interval like on the 1st graph - it's not (how much my_metric was increased over 4 month period at 08/14?, at 08/20?, .., at 11/30? always bigger and bigger since the range is a huge).

The details how exactly it's calculated and nuances (such as "why increase might return floating point number") are already described, f.e. see the answers at this post.

Aggregations

So my question is do I have the right approach for what I am trying to do?

Since you don't use labels, the query might be simplified:

sum(increase(my_metric[$__range])) ---> increase(my_metric[$__range]).

sum as an aggregation operator is especially useful with without and by optional clauses.

F.e. if you have my_metric being reported by several machines, labeled with instance label and you want the aggregate it away in a query (i.e. you don't care about each instance results but want them as a whole), you might want to use:

sum without (instance) (increase(my_metric[$__range]))

🌐
Grafana
community.grafana.com › time series panel
Monitor that Counter increases by exactly 1 for a given time period - Time Series Panel - Grafana Labs Community Forums
January 18, 2022 - Hi everyone! I have an application that provides me with Prometheus metrics that I use Grafana to monitor. One of these metrics is a Prometheus Counter() that increases with 1 every day somewhere between 4PM and 6PM. I…
🌐
Grokipedia
grokipedia.com › troubleshooting prometheus counters in grafana
Troubleshooting Prometheus Counters in Grafana — Grokipedia
January 14, 2026 - Prometheus counters are a fundamental metric type in the Prometheus open-source monitoring and alerting toolkit, originally developed at SoundCloud in 2012, designed to track cumulative, monotonically increasing values such as total request ...
🌐
Grafana
community.grafana.com › prometheus
Unexpected results with increase() function for Counter Metric in Grafana/Prometheus - Prometheus - Grafana Labs Community Forums
December 6, 2024 - What Grafana version and what operating system are you using? Grafana v10.1.0 (ff85ec33c5) What are you trying to achieve? I am trying to calculate the total number of requests in a specific period of time. How are you trying to achieve it? By using the increase() function over a time range.
🌐
Grafana
community.grafana.com › prometheus
Displaying counter metrics - Prometheus - Grafana Labs Community Forums
January 10, 2020 - Hi, I need help dealing with ‘counter’ metrics. Basically I am querying network interface stats. As part of this I have metrics ‘BytesIn’ and ‘BytesOut’. Both of them are counters, and doesnt represent the bandwidth, wh…
🌐
Prometheus
prometheus.io › docs › tutorials › visualizing_metrics_using_grafana
Visualizing metrics using Grafana | Prometheus
Join PromCon EU 2026 , the Prometheus users conference, on October 7–8, 2026 in Munich. PromCon EU 2026 — Oct 7–8, Munich. ... In this tutorial we will create a simple dashboard using Grafana to visualize the ping_request_count metric that we instrumented in the previous tutorial.
🌐
Grafana
community.grafana.com › t › correct-representation-of-counter-metrics › 105654
Correct representation of counter metrics - Grafana - Grafana Labs Community Forums
October 16, 2023 - Hello, I wanted to understand the correct representation of counter metrics prometheus. I have one counter metrics coming from prometheus data source and I need help in its correct representation on time-series graph. I am fetching some value and as per graph, there was a positive value “1” ...
🌐
Grafana
community.grafana.com › dashboards
Dashboard Grafana, Prometheus, several counters - how calculate sum? - Dashboards - Grafana Labs Community Forums
October 9, 2023 - Hi. I have several counters from Prometheus. How can I calculate the total quantity over a period of time? In this case - 72. I have already tried the options with increase, last_over_time. Also, it was not possible …
🌐
OneUptime
oneuptime.com › home › blog › how to create counter over time graph in prometheus
How to Create Counter Over Time Graph in Prometheus
December 17, 2025 - Learn how to properly visualize Prometheus counters over time using rate(), increase(), and irate() functions. This guide covers common pitfalls and best practices for counter visualization.
🌐
Grafana
community.grafana.com › configuration
Adding the counter metric from two different time range for the same prometheus metric - Configuration - Grafana Labs Community Forums
August 24, 2021 - Hi All, I have created a counter metric in python using Prometheus client which counts the number of images processed. I am visualizing the same in grafana. However when I stop my code containing the prometheus client and restart the counter restarts from 0. I can still see the previous metric in grafana.