QubitProducts / exporter_exporter

A reverse proxy designed for Prometheus exporters
Apache License 2.0
336 stars 55 forks source link

Support for cached scrapping #26

Closed michael-doubez closed 4 years ago

michael-doubez commented 4 years ago

Sometimes, I need to time the scraping of an endpoint or to run a script less frequently than the minimum scrape interval (~5min in prometheus before declaring the data stale). This may happens when the scraping may have a cost (contention, costly operations or on weak servers) and

The idea would be to add the possibility to cache the result of the scrape and set a stamp on it. When the next scrape arrives

Currently, the only way to achieve that is to write the result in a promfile, execute the script at the wanted interval and use node_exporter to collect it. It adds a lot of setup for such a simple use case.

In terms of configuration, it could be something similar to HTTP configuration:

 somescript:
    method: exec
    ...
    cache:
        enabled: True
        max_age: 30m
    exec:
      command: /tmp/don_t_launch_that_too_often.sh

Another nice addition for the HTTP method would be the possibility to make a HEAD request on the endpoint to at least check if it is up but this would depend on the exporter supporting it.

tcolgate commented 4 years ago

You can write to promfile, then use an exporter_exporter exec target to cat it. I'd consider adding support for reading a file. Cacheingis better done elsewhere

michael-doubez commented 4 years ago

Yes, that's how I implement it right now: I have a generic python script that acts as a proxy to other modules and uses the file change time to compute aging. But yet, it requires python installed and a writeable space.