-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Un-incremented counters don't have value 0 #118
Comments
Not sure what the "correct" behaviour is in this case, you could also argue that it shouldn't have any value at all until you have set any. A workaround in your case is to inc with 0 just after you created it |
Thanks for the workaround suggestion. Here are my thoughts:
I think we should always print the value of counters, even if they're zero. A missing counter is != than a counter which was never initialized. What do you think? |
I agree with @paulborza. It also matches what the java client does. import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.exporter.common.TextFormat;
import java.io.StringWriter;
import java.util.Collections;
public class App {
static Counter c = Counter.build("name", "help").register();
public static void main(String[] args) throws Exception {
StringWriter writer = new StringWriter();
TextFormat.write004(writer, CollectorRegistry.defaultRegistry.filteredMetricFamilySamples(Collections.<String>emptySet()));
System.out.println(writer.toString());
}
} Prints
|
Should be the same for all types of metrics. import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
import io.prometheus.client.Summary;
import io.prometheus.client.exporter.common.TextFormat;
import java.io.StringWriter;
import java.util.Collections;
public class App {
static {
Counter.build("counter", "help").register();
Gauge.build("gauge", "help").register();
Histogram.build("histogram", "help").register();
Summary.build("summary", "help").register();
}
public static void main(String[] args) throws Exception {
StringWriter writer = new StringWriter();
TextFormat.write004(writer, CollectorRegistry.defaultRegistry.filteredMetricFamilySamples(Collections.<String>emptySet()));
System.out.println(writer.toString());
}
}
|
Alright 🙂 then we should update prom-client to follow Prometheus docs 🙂 |
One can call |
I did discover something interesting though; if adding a label, they are not shown. This might be a bug in the java implementation though, not sure. Seems inconsistent. import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Counter;
import io.prometheus.client.Gauge;
import io.prometheus.client.Histogram;
import io.prometheus.client.Summary;
import io.prometheus.client.exporter.common.TextFormat;
import java.io.StringWriter;
import java.util.Collections;
public class App {
static {
Counter.build("counter", "help").labelNames("label").register();
Gauge.build("gauge", "help").labelNames("label").register();
Histogram.build("histogram", "help").labelNames("label").register();
Summary.build("summary", "help").labelNames("label").register();
}
public static void main(String[] args) throws Exception {
StringWriter writer = new StringWriter();
TextFormat.write004(writer, CollectorRegistry.defaultRegistry.filteredMetricFamilySamples(Collections.<String>emptySet()));
System.out.println(writer.toString());
}
}
|
With labels present there's no way to know the label values to display a default zero. However, once you've initialized the "child" with the label values by calling the |
* Fix counter initialization * Init gauges to 0 * Init histograms to 0 * Init summary to 0 * Add snapshot test for empty metrics * Don't init metrics with labels * Move requires in test * Update changelog Fixing #118
Published in 10.0.1! |
When I navigate to my metrics endpoint, some counters don't have values because they were never incremented. Such a counter is the
unknown_failure_total
which gets incremented on unhandled exceptions.I have Prometheus hooked up to Grafana and it keeps alerting me that there's missing data for some counters. 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
andTYPE
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 be incremented?Thanks!
The text was updated successfully, but these errors were encountered: