found the answer I did add a block like this
static { CD_PRODUCT_SUCCESS_CREATED .labels("podname"); ... }
for all the metrics and now I could see the 0.0 value for the metrics
Answer from R0b0t0 on Stack OverflowInitializing prometheus counters to 0 whenever a new time series is created - Stack Overflow
I could work this out via Prometheus queries where I needed to count from zero, but the metrics were created with one after the first scrape. increase(sum(last_over_time(my_custom_counter_total[$__range]) or vector(0))[$__range:1m]) More on stackoverflow.com
promql - Defaulting a prometheus counter metric to 0 - Stack Overflow
I'm facing a nightmarishly hard problem to solve for something that seems so trivial. Ultimately, I'm trying to detect a single increment of a counter metric in PromQL when there was no data previo... More on stackoverflow.com
RFC: Counter initialisation
The solution to this problem is described in the Prometheus website: export 0 (or NaN, if 0 would be misleading) for any time series you know may exist in advance. Note that this solution does not cover the cases where the Prometheus scrape window did not catch the counter value at 0. For metrics without labels this is as simple as initialising ... More on github.com
Set Prometheus Counter value to 0 - Stack Overflow
I want to set Prometheus Counter value to 0 when the server restarts in a manner similar to, private static final Gauge SERVER_UP = Gauge.build(MetricConstants.SERVER_UP, "Server status"). More on stackoverflow.com
Google Groups
groups.google.com › g › prometheus-users › c › w69L7w6Z5y0
A solution for counters automatic initialization to 0
October 6, 2022 - The workaround consist in manually initializing our metrics to 0. This can become complex with vectors when we don't know in advance the combination of label values, moreover we need to be sure the first scrape from Prometheus include this 0 value. At Goto.com we implemented a solution to this ...
Top answer 1 of 2
3
For anyone interested, here is the solution in promql to detect a single instance of the metric:sum(max_over_time(metric{status="success", env="$env"}[5m]) or vector(0)) - sum(max_over_time(metric{status="success", env="$env"}[5m] offset 5m) or vector(0))
2 of 2
1
One way around it is to use a mix of sequence and generate inputs:
input:
sequence:
inputs:
- generate:
count: 1
mapping: root = ""
processors:
- metric:
type: counter
name: test
labels:
foo: bar
- mapping: root = deleted()
- your_actual_input:
# ...
The message created by the generate input is used to set that test metric and then it's discarded.
Stack Overflow
stackoverflow.com › questions › 62782007 › set-prometheus-counter-value-to-0
Set Prometheus Counter value to 0 - Stack Overflow
private static final Gauge SERVER_UP = Gauge.build(MetricConstants.SERVER_UP, "Server status").labelNames(labels).register(); Gauge gauge = (Gauge) map.get(SERVER_UP); gauge.labels(serviceName, serviceType).set(0);
Robust Perception
robustperception.io › why-predeclare-metrics
Why predeclare metrics? – Robust Perception | Prometheus Monitoring Experts
August 13, 2018 - If you look at a typical use of ... with metrics, metrics that only some times exist are difficult to deal with in PromQL. By declaring the metric before your application uses it, the client library can initialise it to 0....
Google Groups
groups.google.com › g › prometheus-users › c › Wy4AwTklIs0
Set Counter Value to 0
I am using increase function to ... is incremented to 0. after second inc() the sum is 1. As a solution, I have initialised the counter to zero (by doing inc(0) ) for all labels in the application code as I know the labels in advance....
Google Groups
groups.google.com › g › prometheus-users › c › BBoVYf714eA
accumulating counter metric that are never incremented since restart
May 3, 2023 - Yes, you should be able to create a counter which publishes its initial value of zero. I'm fairly sure I've done this with the Golang client some time in the past. What language and client library are you using? You'll have to initialise the counters explicitly.
GitHub
github.com › siimon › prom-client › issues › 118
Un-incremented counters don't have value 0 · Issue #118 · siimon/prom-client
June 17, 2017 - I don't want to suppress this alert because missing data could also mean that Grafana is not able to reach my Prometheus server. The HELP and TYPE statements are printed even for un-incremented counters, but their zero value is not. Should a 0 value be printed for counters which have yet to ...
Author: siimon
GitHub
github.com › open-telemetry › opentelemetry-java › discussions › 5939
Support initial value in counters (Prometheus exporter) · open-telemetry/opentelemetry-java · Discussion #5939
October 25, 2023 - LongCounter MyCounter = meter .counterBuilder("my_app_my_counter") .withInitialValue(0) // <-- explicit initial value makes the value reported to Prometheus .build(); For completeness, here's the code we use to expose metrics to Prometheus thanks to OpenTelemetry Prometheus module: import io.opentelemetry.exporter.prometheus.PrometheusHttpServer PrometheusHttpServer prometheusServer = ...
Author: open-telemetry
Javadoc.io
javadoc.io › doc › io.prometheus › simpleclient › 0.0.10 › io › prometheus › client › Counter.html
Counter (Prometheus Java Simpleclient 0.0.10 API)
Bookmarks · Latest version of io.prometheus:simpleclient · https://javadoc.io/doc/io.prometheus/simpleclient · Current version 0.0.10 · https://javadoc.io/doc/io.prometheus/simpleclient/0.0.10 · package-list path (used for javadoc generation -link option) · https://javadoc.io/doc/io....
Google Groups
groups.google.com › g › prometheus-users › c › uhJ9UUAF3Hg
First value of increase(Counter[Time]) doesn't count
July 4, 2023 - The counter may have been running and incrementing for a long time, before Prometheus starts scraping it; the first value you see could represent days or years of accumulation. That's why rate() and increase() only give a value if there are two or more adjacent data points. It's the only way to be sure that the value has actually increased over that time period. And if you don't generate an initial timeseries value of zero, then it can only use the next two values to calculate a rate between those two values.