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

Running custom metrics in background #262

Open
BohdanKaminskyi opened this issue Aug 16, 2023 · 5 comments
Open

Running custom metrics in background #262

BohdanKaminskyi opened this issue Aug 16, 2023 · 5 comments

Comments

@BohdanKaminskyi
Copy link

Hey there,
from the README.md I understand that if ".add()" method is not used, default metrics are executed in the background.
What I'm trying to do - is to execute also custom metrics in background.

Is it possible?

@trallnag
Copy link
Owner

Hi Bohdan, when you say custom metrics, do you mean additional "instrumentation functions" or just any Prometheus metric like a counter unrelated to PFI?

In any case both is possible.

For 1., the default set of instrumention metrics for PFI is in a dedicated function. So you can add both, the default set and additional functions, with add().

For 2., it should just work. PFI uses the official prometheus library under the hood.

@BohdanKaminskyi
Copy link
Author

@trallnag Thx for the answer, would you mind answering one more question?:)
I need to increase counter value basically in one of my endpoints. But I'm not sure how to register that counter without closure.
I mean, in examples, the counter lives in closure, and only accessible from it, but that way I cannot use it from endpoint

@trallnag
Copy link
Owner

Accessing metrics defined within these closures is not possible from endpoint functions, I'm afraid. At least to my knowledge. Why do you want to access it from endpoint?

Can't you define the metric yourself somewhere outside the endpoint and reference it then? Basically not using PFI and just using prometheus client library?

@BohdanKaminskyi
Copy link
Author

I'm trying to do so, and it looks like PFI still adds this metric into metrics endpoint (that's good:))

@EasyAsABC123
Copy link

@BohdanKaminskyi can you provide this as an example?

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