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

Provide a way to set a Counter to an absolute value #252

Open
K900 opened this issue Dec 4, 2024 · 6 comments
Open

Provide a way to set a Counter to an absolute value #252

K900 opened this issue Dec 4, 2024 · 6 comments

Comments

@K900
Copy link

K900 commented Dec 4, 2024

I'm writing a reexporter for another service that already outputs aggregated metrics (but not in a Prometheus compatible format). It would be very convenient to be able to directly call .set(existing_value) on a Prometheus counter, instead of having to track the previous value manually and inc_by a computed amount.

@mxinden
Copy link
Member

mxinden commented Dec 5, 2024

@K900
Copy link
Author

K900 commented Dec 5, 2024

AFAIUI const counters just can't be changed at all? I want to be able to change the value, I just already have it pre-aggregated.

@mxinden
Copy link
Member

mxinden commented Dec 5, 2024

You would use the Collector trait to implement your own metrics collector. On a scrape of your exporter by Prometheus, prometheus_client would call Collector::collect. Your collector implementation would retrieve the metric values from your actual monitoring target, and expose the values via e.g. ConstCounter. See Collector docs for details.

Hope this is helpful.

@K900
Copy link
Author

K900 commented Dec 5, 2024

Hmm, this would require a lot of refactoring, but I think it could work.

@K900
Copy link
Author

K900 commented Dec 5, 2024

Actually, maybe not... Getting values from the target is async right now, and Collector's interface is sync, so I'd have to block...

@K900
Copy link
Author

K900 commented Dec 19, 2024

OK so some refactoring later, it looks like I can't really do this without Collector being async, or using my own atomics or whatever to store 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

2 participants