简体   繁体   中英

Prometheus json metrics

The application I want to monitor provides an api endpoint for health checks that responds with metrics in json. As an example:

$ curl  https://example.com/api/stats
{"status":"success","code":0,"data":{"UserCount":140,"UserCountActive":23}}

I have setup the Prometheus blackbox_exporter to monitor that this endpoint returns 200 Ok however I'd ideally like to get those metrics too. I understand instrumentation exports this data directly from the application. But since the application is already exporting what I want in a json object, I would prefer the convenience of not maintaining my own fork of this software to include the Prometheus libraries necessary for instrumentation. How should I consume metrics that are in json?

There is currently no official exporter to scrape JSON endpoint. Maybe because it is easy to write one from scratch and any general solution must use some default behaviors like building the name of the metric from the path to the data which doesn't take into account the type of the metric ; or any relevant label to apply or parse date to name a few.

You will easily find available JSON exporters with your preferred search engine. They can readily replace the blackbox_exporter. And they should be a good fit given the sample provided.

One solution, I would like to mention is the exporter_exporter because I have found it useful for implementing rapidly an exporter while waiting for an adhoc one. It can be used to execute scripts that produce prometheus metrics. In your case, it is quite easy to write a python script that scrape a Json endpoint and use it to write the corresponding prometheus format in standard output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM