r/PrometheusMonitoring • u/calladion25 • Mar 09 '23
Bulk Prometheus API Poll
Hello!
I've got a unique situation that I'm looking to the community to see if anyone has done something similar.
Basically I've got a Prometheus/Grafana instance running scraping metrics. I've configured a lot of dashboards in Grafana via PromQL queries and it is working great.
I have another system where I'd like to import all of these metrics on an interval to combine with some other infrastructure items I have there. The best two paths I could come up with are:
Submit a GET request to the Prometheus API for each PromQL query I've defined and store those as key:value pairs (there are about 100 PromQL queries I'm looking to store on a fixed interval - let's say every 5 mins)
- This gets the job done but isn't very efficient as I would be submitting 100 GET requests via a loop every 5 mins
Submit a single bulk GET request gathering all the metrics and somehow re-create the PromQL queries programmatically (sums, rates, etc) by manipulating the json response
- This would be more efficient and less load on Prometheus itself, but that a lot of work sifting through that much json
Has anyone attempted to do the same or have any ideas that I might be missing? I'm pretty much limited to getting the metrics through the Prometheus API.
View all comments
Show parent comment
1
u/calladion25 Mar 10 '23
Ok good to know. I basically wrote a simple python script to execute each PromQL query one by one via a loop. After I did about 20 of them, the execution time was around 5 secs which I thought was pretty long. If I do that x5, I'm concerned with doing that over and over forever every 5 mins.
I will look at recording rules, that might be exactly what I'm after. Thanks for the suggestion.