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

Why are default metrics collected on an interval? #307

Closed
Hornwitser opened this issue Dec 14, 2019 · 2 comments
Closed

Why are default metrics collected on an interval? #307

Hornwitser opened this issue Dec 14, 2019 · 2 comments

Comments

@Hornwitser
Copy link

Hornwitser commented Dec 14, 2019

Prometheus sends requests to the monitored application to collect metrics, and you configure the interval this happens in Prometheus. It would then make sense that default metrics are collected when Prometheus requests them. Right?

So why is it that prom-client provides no way to collect default metrics on demand and instead opt collect them on an interval? The Prometheus docs on writing exporters says and I quote:

Metrics should only be pulled from the application when Prometheus scrapes them, exporters should not perform scrapes based on their own timers. That is, all scrapes should be synchronous.

Accordingly, you should not set timestamps on the metrics you expose, let Prometheus take care of that. If you think you need timestamps, then you probably need the Pushgateway instead.

Furthermore the writing client libraries document has this to say:

Clients MUST be written to be callback based internally. Clients SHOULD generally follow the structure described here.

The key class is the Collector. This has a method (typically called ‘collect’) that returns zero or more metrics and their samples. Collectors get registered with a CollectorRegistry. Data is exposed by passing a CollectorRegistry to a class/method/function "bridge", which returns the metrics in a format Prometheus supports. Every time the CollectorRegistry is scraped it must callback to each of the Collectors’ collect method.

There is no such collect method to Collectors in this library, there's only the synchronous get method which leads me to conclude that this library's core design is a canonical example of doing Prometheus wrong.

@zbjornson
Copy link
Collaborator

Yeah, that's issue #180. PRs welcome.

@Hornwitser
Copy link
Author

I tried searching for this before opening an issue and couldn't find anything 😳.

I have looked at the codebase for implementing this and err, I ended up writing my own Prometheus client from scratch instead.

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

No branches or pull requests

2 participants