Prometheus APIs and Metrics

484 views
Skip to first unread message

akshaywa...@gmail.com

unread,
Sep 6, 2018, 1:28:43 PM9/6/18
to Prometheus Users
Hi All,

How do we retrieve alerts, rules and metrics via API, the way we get that on the Prometheus expression browser? What are the APIs available for Prometheus (looking for a list of available APIs)? Is it possible to get all the information that we get on the Prometheus dashboard via Prometheus APIs?

For Example:

I am able to get the targets via API($curl http:localhost:9090/api/v1/targets) and config ($curl http:localhost:9090/api/v1/status/config) but how do I get the alerts, flags, rules and any other information that we see on Prometheus Dashboard via APIs? I ran the below API calls but I am getting method not allowed error:

Method Not Allowed

Method Not Allowed

Method Not Allowed

Method Not Allowed

Method Not Allowed

Method Not Allowed


$ curl "http://localhost:9090/api/v1//status/service-discovery"
<a href="/api/v1/status/service-discovery">Moved Permanently</a>.

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Also for getting the metrics, do we need to grab the scrap url for ex. scrap url for node-exporter when we run /api/v1/targets and then run then run that scrap url to get the scraped metrics?

For Ex:
When I run targets api, it gives me localhost target:
$ curl "http://localhost:9090/api/v1/targets"
{"status":"success","data":{"activeTargets":[{"discoveredLabels":{"__address__":"localhost:9090","__metrics_path__":"/metrics","__scheme__":"http","job":"prometheus"},"labels":{"instance":"localhost:9090","job":"prometheus"},"scrapeUrl":"http://localhost:9090/metrics","lastError":"","lastScrape":"2018-09-06T12:22:20.365793767-05:00","health":"up"}],"droppedTargets":[]}}  


And then I run the below api to get the scraped metrics:


Is this the correct way to retrieve the metrics Information?

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages