client_python icon indicating copy to clipboard operation
client_python copied to clipboard

Collect metrics on scrape instead of timer

Open nonamethanks opened this issue 1 year ago • 1 comments

The prometheus docs on exporters say:

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.

The very first example provided by this repository goes against those docs by just spamming the same function on a timer.

Can anyone provide a basic example that shows how to start a metrics collection only when prometheus connects to the exporter, as it's actually supposed to be done? Because christ, it's faster to just set up a flask server with a custom /metrics endpoint than actually figure out how to do so using this framework.

nonamethanks avatar Oct 03 '24 22:10 nonamethanks

If you are interested in creating an exporter see the custom collectors section of the docs: https://prometheus.github.io/client_python/collector/custom/.

csmarchbanks avatar Oct 08 '24 15:10 csmarchbanks