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

Initialising metrics with empty labels and 0 values, why? #29

Open
tykling opened this issue Feb 19, 2023 · 2 comments
Open

Initialising metrics with empty labels and 0 values, why? #29

tykling opened this issue Feb 19, 2023 · 2 comments

Comments

@tykling
Copy link

tykling commented Feb 19, 2023

Hello,

To avoid a timeseries with value 0 and None as label values for each metric I have added the following change in metric.py in my fork: master...tykling:prometheus_express:master#diff-20f2aa2ee0a5700a512201202c3883d8098072fb9d63cb24f5ba5316f5c52f3d

Am I missing something or can this be removed with no negative consequences?

I will open a PR if you agree it can be removed.

Thanks! 👍 :)

@ssube
Copy link
Owner

ssube commented Feb 19, 2023

It's been a little while since I wrote that, but if I remember correctly, it was a poorly-implemented attempt to satisfy Prometheus' "metrics should not appear or disappear" rule (https://prometheus.io/docs/practices/instrumentation/#avoid-missing-metrics).

I think there are arguments both for and against following the Prometheus rule in an embedded, low-memory device, and removing that is probably fine. Alternatively, it would be much better to let the user provide a set of labels they expect to use, instead of making up a new series with Nones.

@kornpow
Copy link

kornpow commented Mar 12, 2024

I do find the default None label value to be kind of annoying. However in order to not have to switch to a fork, I do this in my code in order to prevent the unnecessary metric stuck at 0.

temp_g = Gauge(
    'temp_gauge',
    'temp sensor gauge',
    labels=['location'],
    registry=registry
)
temp_g.values = {}

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