prom2json

Background

(Pre-)historically, Prometheus clients were able to expose metrics asJSON. For various reasons, the JSON exposition format was deprecated.

Usually, scraping of a Prometheus client is done by the Prometheusserver, which preferably happens with the protocol bufferformat. Sometimes, a human being needs to inspect what a Prometheusclients exposes. In that case, the text format is used (which isotherwise meant to allow simplistic clients like shell scripts toexpose metrics to a Prometheus server).

However, some users wish to scrape Prometheus clients with programsother than the Prometheus server. Those programs would usually use theprotocol buffer format, but for small ad hoc programs, that is toomuch of an (programming) overhead. JSON comes in handy for theseuse-cases, as many languages offer tooling for JSON parsing.

To avoid maintaining a JSON format in all client libraries, theprom2json tool has been created, which scrapes a Prometheus clientin protocol buffer or text format and dumps the result as JSON tostdout.

This will dump the JSON to stdout. Note that the dumped JSON isnot using the deprecated JSON format as specified in thePrometheus exposition formatreference. Thecreated JSON uses a format much closer in structure to the protocolbuffer format. It is only used by the prom2json tool and has nosignificance elsewhere. See below for a description.

A typical use-case is to pipe the JSON format into a tool like jq torun a query over it. That looked like the following when the clientsstill supported the deprecated JSON format:

$ curl http://my-prometheus-client.example.org:8080/metrics | jq .

Now simply use prom2json instead of curl (and change the querysyntax according to the changed JSON format generated by prom2json):