count(count by (a) (hello_info))
First you want an aggregator with a result per value of a, and then you can count them.
client_python
prometheus.github.io › client_python › instrumenting › labels
Labels | client_python
April 9, 2026 - Metrics with labels are not initialized when declared, because the client can’t know what values the label can have. It is recommended to initialize the label values by calling the .labels() method alone: from prometheus_client import Counter c = Counter('my_requests_total', 'HTTP Failures', ['method', 'endpoint']) c.labels('get', '/') c.labels('post', '/submit')
Prometheus
prometheus.io › docs › practices › naming
Metric and label naming | Prometheus
A common argument is that those pieces of information are already defined somewhere else (e.g. schema, metadata, other labels, etc.). Prometheus strongly recommends including unit and type in a metric name, even if you store that information elsewhere, because of the following practical reasons:
Top answer 1 of 4
119
count(count by (a) (hello_info))
First you want an aggregator with a result per value of a, and then you can count them.
2 of 4
18
Other example: If you want to count the number of apps deployed in a kubernetes cluster based on different values of a label( ex:app):
count(count(kube_pod_labels{app=~".*"}) by (app))
client_java
prometheus.github.io › client_java › getting-started › labels
Labels | client_java
Counter counter = Counter.builder() .name("payments_total") .help("total number of payments") .constLabels(Labels.of("env", "dev")) .labelNames("type", "status") .register(); However, most use cases for constLabels() are better covered by target labels set by the scraping Prometheus server, or by one specific metric (e.g.
GitHub
github.com › prometheus › client_golang › discussions › 1073
Dynamically add labels in a Counter or CounterVec · prometheus/client_golang · Discussion #1073
If you already have instrumented your code so that you can provide metrics for Datadog, then you probably don't want to duplicate every madeUpDataDogAPI.Counter.Inc() line with a counter.Inc() where counter is a prometheus.Counter. Ideally, you can tap into whatever metrics you already have and create them at scrape time with NewConstMetric. Having said that, it is possible in Prometheus to set an empty label value, with is (almost) completely equivalent to not having set that label at all.
Author: prometheus
Stack Overflow
stackoverflow.com › questions › 57261955 › different-set-of-labels-for-the-same-counter-name
prometheus - Different set of labels for the same counter name? - Stack Overflow
"Every time series is uniquely identified by its metric name and optional key-value pairs called labels. " -so looks like I can create a counter "counter_name" with label: key1 => value1 and it will create this time series determined by counter_name ...
Iximiuz
iximiuz.com › en › posts › prometheus-metrics-labels-time-series
Prometheus Cheat Sheet - Basics (Metrics, Labels, Time Series, Scraping)
If a target reports a gauge (i.e., instant measurement) metric that changes more frequently than it's scraped, the intermediate values will never be seen by the Prometheus node. Thus, it may cause blindness of the monitoring system to some bizarre patterns: Obviously, counter (i.e., monotonically incrementing measurement) metrics don't have such a problem.
Prometheus
prometheus.io › docs › practices › instrumentation
Instrumentation | Prometheus
A Java counter takes 12-17ns to increment depending on contention. Other languages will have similar performance. If that amount of time is significant for your inner loop, limit the number of metrics you increment in the inner loop and avoid labels (or cache the result of the label lookup, for example, the return value of With() in Go or labels() in Java) where possible.
HexDocs
hexdocs.pm › prometheus_ex › Prometheus.Metric.Counter.html
Prometheus.Metric.Counter — Prometheus.ex v5.1.0
Counter is a Metric that represents a single numerical value that only ever goes up. That implies that it cannot be used to count items whose number can also go down, e.g. the number of currently running processes. Those "counters" are represented by Prometheus.Metric.Gauge.
INNOQ
innoq.com › en › blog › 2019 › 05 › prometheus-counters
Prometheus Counters and how to deal with them – INNOQ
May 20, 2019 - Whenever we increment the counter, we specify the appropriate values for those labels (e.g. country='DE', payment_method='INVOICE' and shipping_method='STANDARD'). With Micrometer we do this by adding pairs of Strings containing the key and value of a label in addition to the counter name. If we query our orders_created_total metric after restarting our sample app, we no longer see only one result but many. Within the curly brackets we ignored so far, we can see the keys and values of our three labels (the other two labels job and instance are automatically added by Prometheus when scraping the values from the several targets).
Go Packages
pkg.go.dev › github.com › prometheus › client_golang › prometheus
prometheus package - github.com/prometheus/client_golang/prometheus - Go Packages
July 24, 2026 - CounterVec is a Collector that bundles a set of Counters that all share the same Desc, but have different values for their variable labels. This is used if you want to count the same thing partitioned by various dimensions (e.g. number of HTTP requests, partitioned by response code and method).
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
OneUptime
oneuptime.com › home › blog › how to implement prometheus counter best practices
How to Implement Prometheus Counter Best Practices
January 30, 2026 - from prometheus_client import Counter, start_http_server # Define counter with labels http_requests_total = Counter( 'myapp_http_requests_total', 'Total number of HTTP requests processed', ['method', 'status', 'endpoint'] ) def handle_request(method, endpoint): try: # Process request...
Google Groups
groups.google.com › g › prometheus-users › c › h9ibD4NZOto
python_client counter with label
I have: counter= Counter(metric, metric, labelnames=['client'], labelvalues=[ data['client'] ]) print counter print dir(counter) counter.inc(diff) <prometheus_client.core._LabelWrapper object at 0xcf8ed0> ['class', 'delattr', 'dict', 'doc', 'format', 'getattribute', 'hash', 'init', 'module', 'new', 'reduce', 'reduce_ex', 'repr', 'setattr', 'sizeof', 'str', 'subclasshook', 'weakref', '_kwargs', '_labelnames', '_lock', '_metrics', '_name', '_samples', '_type', '_wrappedClass', 'collect', 'describe', 'labels', 'remove']
Prometheus
prometheus.io › docs › concepts › metric_types
Metric types | Prometheus
In the future, Prometheus might handle other metric types as composite types, too. There is also ongoing work to persist the type information of the simple float samples. A counter is a cumulative metric that represents a single monotonically increasing counter whose value can only increase or be reset to zero on restart.