Skip to content
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

Prometheus exporter exports Counters as Gauges #722

Open
worldspawn opened this issue Nov 17, 2021 · 2 comments
Open

Prometheus exporter exports Counters as Gauges #722

worldspawn opened this issue Nov 17, 2021 · 2 comments

Comments

@worldspawn
Copy link

The export text is:

# HELP uploads_documentuploads
# TYPE uploads_documentuploads gauge
uploads_documentuploads{planid="9aa6dd9e8e7axxxxx1414621fe9b3249",userid="xxxxxxx-5a2f-47fe-b2f1-865b14661aa1",domain="gmail.com",clientid="5e9d38cc0c7771fe1b6e7bd4bbd5bedd"} 0

for a counter created and incremented with:

_options = new CounterOptions { Name = name, MeasurementUnit = unit, Context = context };
_metricsRoot.Measure.Counter.Increment(_options, metricTags, delta);

Not that I'm comparing :) but prometheus.net exports a counter as Type counter

# HELP metrictest01_ticks_total Just keeps on ticking
# TYPE metrictest01_ticks_total counter

Seems broken

@mt89vein
Copy link

I think there is no error. Counter has also decrement method. Metric that can go up and down should be with type Gauge in prometheus.

@danm-de
Copy link

danm-de commented Sep 1, 2022

@alhardy

Why was it decided that counters should have a decrement method? What are the use cases for this? Are there any scenarios where I actually want to count backwards?

I don't understand the meaning of the example. (https://www.app-metrics.io/getting-started/metric-types/counters/#using-counters). Why should I decrease the number of emails sent? It's an event in the past, I can't undo it.

var sentEmailsCounter = new CounterOptions
{
    Name = "Sent Emails",
    MeasurementUnit = Unit.Calls
};

_metrics.Measure.Counter.Increment(sentEmailsCounter);
_metrics.Measure.Counter.Decrement(sentEmailsCounter);
_metrics.Measure.Counter.Increment(sentEmailsCounter, 10);
_metrics.Measure.Counter.Decrement(sentEmailsCounter, 10);

I realize that Prometheus isn't the only data output sink, but I think their definition of a counter is pretty correct. (https://prometheus.io/docs/concepts/metric_types/#counter)

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. [..] Do not use a counter to expose a value that can decrease. For example, do not use a counter for the number of currently running processes; instead use a gauge.

An external application (such as Prometheus) can easily detect when the counter has been reset (next value < previous value) and accumulate the values ​​accordingly.

However, this condition does not work if a decrement was performed programatically. Not to be confused with Reset (at program restart).

This is probably the reason why gauge is exported as TYPE. Unfortunately, evaluations for COUNTER do not work with GAUGE type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants