count(count by (a) (hello_info))

First you want an aggregator with a result per value of a, and then you can count them.

Answer from brian-brazil on Stack Overflow
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › operators
Operators | Prometheus
In case the threshold value is not aligned to one of the bucket boundaries of the histogram, either linear (for NHCB and zero buckets of exponential histogram) or exponential (for non zero bucket of exponential histogram) interpolation is applied to compute the estimated count of observations that remain in the bucket containing the threshold. In case when some observations get trimmed, the new sum of observation values is recomputed (approximately) based on the remaining observations. The following binary comparison operators exist in Prometheus:
People also ask

What are Prometheus metrics?
Prometheus metrics are structured time series built on a flexible data model. Each metric includes a name, labels, a sample value, and a timestamp. Samples are collected at intervals and queried using PromQL.
🌐
last9.io
last9.io › blog › prometheus-metrics-types-a-deep-dive
Prometheus Metrics Types - A Deep Dive | Last9
What is the format of Prometheus metrics?
Prometheus metrics use a plaintext exposition format served over HTTP. Each line includes a metric name, an optional label set, and a value. Example: http_requests_total{method="GET", code="200"} 1027
🌐
last9.io
last9.io › blog › prometheus-metrics-types-a-deep-dive
Prometheus Metrics Types - A Deep Dive | Last9
What are the types of metrics in Prometheus?
Prometheus supports four metric types: Counter, Gauge, Histogram, and Summary. Each type offers distinct capabilities for tracking different system behaviors.
🌐
last9.io
last9.io › blog › prometheus-metrics-types-a-deep-dive
Prometheus Metrics Types - A Deep Dive | Last9
🌐
OpenObserve
openobserve.ai › home › blog › prometheus metrics count basics
Prometheus Metrics Count Basics
September 26, 2025 - These data points are stored as time series, and each unique combination of metric name and labels becomes a separate time series. When you run a count query, Prometheus looks at all the relevant time series and performs calculations on them.
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
The float samples in b are considered the counts of observations in each bucket of one or more classic histograms. Each float sample must have a label le where the label value denotes the inclusive upper bound of the bucket. (Float samples without such a label are silently ignored.)
🌐
OneUptime
oneuptime.com › home › blog › how to count unique label values in prometheus
How to Count Unique Label Values in Prometheus
December 17, 2025 - Use count(group by (label_name) (metric_name)) to count unique label values · The group aggregation operator deduplicates time series by label combinations · Use Grafana's label_values() query helper for dropdown variable population · Monitor ...
🌐
Promlabs
promlabs.com › promql-cheat-sheet
PromLabs | PromQL Cheat Sheet
Available aggregation operators: sum(), min(), max(), avg(), stddev(), stdvar(), count(), count_values(), group(), bottomk(), topk(), quantile()
Find elsewhere
🌐
Grafana
community.grafana.com › t › how-to-calculate-the-number-of-requests-in-a-time-period-using-promql › 136815
How to calculate the number of requests in a time period using PromQL - Grafana - Grafana Labs Community Forums
November 21, 2024 - Hello, community! I am building a dashboard in Grafana to monitor the latency and the number of requests made to a specific API. The metrics are being collected via Google Cloud Managed Service for Prometheus and access…
🌐
VictoriaMetrics
victoriametrics.com › blog › prometheus metrics explained: counters, gauges, histograms & summaries
Prometheus Metrics Explained: Counters, Gauges, Histograms & Summaries
February 21, 2025 - Additionally, Prometheus introduced native histograms in version v2.40.0. A summary works similarly to a histogram, but the key difference is where quantiles are estimated. With histograms, data points are sorted into predefined buckets, stored as cumulative counts, and quantiles are estimated ...
🌐
Last9
last9.io › blog › prometheus-metrics-types-a-deep-dive
Prometheus Metrics Types - A Deep Dive | Last9
June 17, 2026 - Why it’s important: Prometheus already attaches timestamps to every data point. You don’t need to add one manually, and doing so just creates unnecessary churn. Counters track values that only go up. They’re used to record totals, events like HTTP requests served, background jobs completed, or errors encountered.
🌐
SigNoz
signoz.io › guides › how to count unique label values with prometheus queries
How to Count Unique Label Values with Prometheus Queries | SigNoz
September 6, 2024 - Prometheus labels are key-value pairs attached to metrics that provide additional context and allow for more detailed data analysis. They play a crucial role in identifying and categorizing metrics, enabling you to slice and dice your data in ...
🌐
MetricFire
metricfire.com › blog › understanding-the-prometheus-rate-function
How the Prometheus rate() function works | MetricFire
March 12, 2026 - Summary: Similar to a histogram, this metric type records a total count of observations and a sum of observed values. It processes the information while computing configurable quantities for a sliding time window.
🌐
Better Stack
betterstack.com › community › questions › prometheus-to-count-unique-label-values
Prometheus Query to Count Unique Label Values | Better Stack Community
December 2, 2024 - To count unique label values in Prometheus, you can use the count function along with the by clause to aggregate metrics based on a specific label.
🌐
Prometheus
prometheus.io › docs › concepts › metric_types
Metric types | Prometheus
the count of events that have been observed, exposed as <basename>_count · See histograms and summaries for detailed explanations of φ-quantiles, summary usage, and differences to histograms. NOTE: Beginning with Prometheus v3.0, the values of the quantile label are normalized during ingestion ...
🌐
Reddit
reddit.com › r/prometheusmonitoring › prometheus counters very unreliable for many use-cases, what do you use instead?
r/PrometheusMonitoring on Reddit: Prometheus counters very unreliable for many use-cases, what do you use instead?
April 14, 2025 -

My team switched from datadog to prometheus and counters have been the biggest pain-point. Things that just worked without thinking about it in datadog doesn't seem to have good solutions in prometheus. Surely we can't be the only ones hitting our head against the wall with these problems? How are you addressing them?

Specifically for use-cases around low-frequency counters where you want *reasonably* accurate counts. We use Created Timestamp and have dynamic labels on our counters (so pre-initializing counters to zero isn't viable or makes the data a lot less useful). That being said, these common scenarios have been a challenge:

  • Alerting on a counter increase when your counter doesn't start at zero. We use Created Timestamp gives us more confidence but it worries me that a bug/edge-case will cause us to miss an alert. Catching that would be difficult.

  • Calculating the total number of increments in a time period (ex: $__range). Sometimes short-lived series aren't counted towards the total.

  • Viewing the frequency of counter increments over time as a time series. Seems like aligning the rate and step helps but I'm still wary about the accuracy. It seems like for some time ranges it doesn't work correctly.

  • For calculating a success rate or SLI over some period of time. The approach of `sum(rate(success_total[30d])) / `sum(rate(overall_total[30d]))` doesn't always work if there are short-lived series within the query range. I see Grafana SLO feature uses recording rules, which I hope(?) improves this accuracy, but its hard to verify and is a lot of extra steps (i.e. `sum(sum_over_time((grafana_slo_success_rate_5m{})[28d:5m])) / sum(sum_over_time((grafana_slo_total_rate_5m{} )[28d:5m]))`

A lot of teams have started using logs instead of metrics for some of these scenarios. Its ambiguous when its okay to use metrics and when logs are needed, which undermines the credibility of our metrics' accuracy in general.

The frustrating thing is it seems like all the raw data is there to make these use-cases work better? Most of the time you can manually calculate the statistic you want by plotting the raw series. I'm likely over-simplifying things, and I know there's complicated edge-cases around counter-resets, missed scrapes, etc., however promql is more likely to understate the `rate`/`increase` to account for that. If anything, it would be better to overstate the `rate` since its safer to have a false positive than false negative for most monitoring use-cases. I rather have grafana widgets or promql that works for the majority of times you don't hit the complicated edge cases but overstates the rate/increase when that does happen.

I know this comes across as somewhat of a rant so I just want to say I know the prometheus maintainers put a lot of thought into their decisions and I appreciate their responsiveness to helping folks here and on slack.

Top answer
1 of 2
12
You're absolutely correct. Very slow moving counters are a difficult issue with Prometheus. What we do: Reduce the cardinality for important SLO metrics We try not to include "debugging level" labels. Too many teams try and add ever single label dimension they would want in debugging which makes the couting very sparse. Metrics are designed to tell you that there is a problem at X time. It's meant to notify you that you should go look in the logs for the actual errors. If your error metrics have labels, maybe re-think their use. For singleton use timestamp metrics I've seen some teams use counters for cron job like things that should be using job_started_timestamp_seconds or job_completed_timestamp_seconds, etc. Use accumulator exporters For some things we actually end up using push with statsd to a single accumulator that Prometheus scrapes. This is typically for queue dispatched workers. The modern approach would be to use something like OTel cumulative deltas and a single Otel aggregation collector. Personally I wish teams would stop over-leaning on queue dispatched ephemeral workers. It's much more reliabile and efficient to have long-running workers than workers that only last a few seconds or minutes. IMO, the whole "FaaS" thing is a bad fad in the industry. It's cute, but when I put on my SRE hat, it says nope. Long term idea I have a long-term idea to add a new metrics pipeline within Promethus itself. My marketing name for this is "Materialized Metrics". Essentially taking counter scrapes and turning them back into deltas. Then you specify which lables to sum by /without () and turns them back into counters. This way you can do things like drop instance or other labels from the counters and get back a single counter projection that doesn't suffer as much from the extrapolation errors. I'm still working on the design doc, there are a lot of edge cases and things to think about. EDIT to add I think your title statement is a bit clickbait. "very unreliable for many use-cases" is exaggeration / hyperbole. Normal counters are very reliable for almost all use cases. Especially when following Prometheus best practices.
2 of 2
3
How do you write data into prometheus? Scraping? Remote writes? I use Prometheus as a database for fio metrics with 1s update interval, and it works great. If you do scraping, rate of scraping is defining how well your data are represented. There is no proper way to handle situation when metric 'starts' not at the 0. You can emulate it a bit with logic, but it will be flawed. Normal Prometheus use imply, that you either worry about actual value (for gauges) or worry about increments, may be, increments over time. A lot of short-lived metrics is an anti-pattern for Prometheus. Reduce cardinality, remove excessive labeling via rewriting rules. Use of recording rules is more reliable than you think, if you cover your recording rules with a proper unit tests (promtool test rules). Write a good tests, set up few alerts for slow recording rules processing and you can be sure, that they work reliably. Contrary: no tests and no alerts, you get a broken monitoring which checks ...something. One problem with Prometheus: it uses floats, so counts are not 100% accurate, especially, if you do '+1' for large numbers. At some value you can't do +1 anymore (around 1052, I belive, 1052+1 == 1052).
🌐
ContentDB
content.luanti.org › help › metrics
Prometheus Metrics - ContentDB
Prometheus Metrics can be accessed at /metrics, or you can view them on the Grafana instance below. View ContentDB on Grafana · contentdb_packages - Total packages (counter). contentdb_users - Number of registered users (counter). contentdb_downloads - Total downloads (counter).
🌐
Paradox Wikis
hoi4.paradoxwikis.com › Achievements
Achievements - Hearts of Iron 4 Wiki
1 month ago - Achievements can only be gained in single-player Ironman games, with the 1936 start, on regular, veteran or elite difficulty. (30 Minutes of Hel and Don’t Die for Your Country can only be completed in the 1939 start date). They can be earned while playing older versions of the game as long as said achievements were present in that version.
🌐
DEV Community
dev.to › zop_8abedcc7e12 › when-autoscaling-makes-your-bill-worse-not-better-285j
When Autoscaling Makes Your Bill Worse, Not Better - DEV Community
April 13, 2026 - If Prometheus scrapes every 15 seconds, KEDA sees data that is up to 45 seconds old (scrape age plus polling delay). Reducing both to 5-10 seconds closes the detection gap for bursty workloads. A well-tuned autoscaling setup has two visible characteristics. First, replica counts are stable during steady-state traffic, moving only when load genuinely changes over a meaningful time window.
🌐
Marathon
marathonthegame.com
Marathon | Homepage
From the creators of Halo and Destiny comes Marathon, Bungie's new team-based extraction shooter.
🌐
Tigera
tigera.io › home › prometheus monitoring › prometheus metrics
Prometheus Metrics: A Practical Guide | Tigera – Creator of Calico
July 30, 2021 - A common next step is a Prometheus Grafana setup, which turns these scraped metrics into shared dashboards and visual panels. ... Counter: A cumulative metric that only goes up, or resets to 0 on restart.