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

In counter have a set value option #12

Closed
Robbo312 opened this issue Apr 10, 2021 · 3 comments · May be fixed by #19
Closed

In counter have a set value option #12

Robbo312 opened this issue Apr 10, 2021 · 3 comments · May be fixed by #19

Comments

@Robbo312
Copy link

Would be handy to have a set value option in the counter like guage. The source I'm using (Total kWh in a energy meter) so I just need to set the value not increase it by a certain amount.

@jdeisenh
Copy link

Seconded.
It's not only handy, but necessary if you want to pass through counters that originate somewhere else.
Making them gauges is simply not an option, it won't handle resets correctly, which is the whole point of having counters.

@matterlobby
Copy link
Contributor

Unfortunately, the underlying library (prom-client) does not support setting values of "Counter" type metrics explicitly:
https://github.com/siimon/prom-client/blob/master/lib/counter.js

As you can see in the code, it includes a setValue function internally, but does not expose it in the Counter class. The only workaround seems to me to first reset the value and then increment by the new value.

@matterlobby matterlobby pinned this issue May 11, 2021
hashworks added a commit to hashworks/node-red-contrib-prometheus-exporter that referenced this issue Oct 8, 2022
@hashworks
Copy link

hashworks commented Oct 8, 2022

#19 solves this by adding a reset parameter, which, if set, resets the metric before the operation. This way this payload behaves like a set operation:

{
    reset: true,
    op: "inc",
    val: 5000,
}

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