Bump actions/checkout from 6.0.3 to 7.0.1 (#291)
Bumps actions/checkout from 6.0.3 to 7.0.1.
updated-dependencies:
- dependency-name: actions/checkout dependency-version: 7.0.1 dependency-type: direct:production update-type: version-update:semver-major …
Signed-off-by: dependabot[bot] support@github.com Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
prom2json
A tool to scrape a Prometheus client and dump the result as JSON.
Background
(Pre-)historically, Prometheus clients were able to expose metrics as JSON. For various reasons, the JSON exposition format was deprecated.
Usually, scraping of a Prometheus client is done by the Prometheus server, which preferably happens with the protocol buffer format. Sometimes, a human being needs to inspect what a Prometheus clients exposes. In that case, the text format is used (which is otherwise meant to allow simplistic clients like shell scripts to expose metrics to a Prometheus server).
However, some users wish to scrape Prometheus clients with programs other than the Prometheus server. Those programs would usually use the protocol buffer format, but for small ad hoc programs, that is too much of an (programming) overhead. JSON comes in handy for these use-cases, as many languages offer tooling for JSON parsing.
To avoid maintaining a JSON format in all client libraries, the
prom2jsontool has been created, which scrapes a Prometheus client in protocol buffer or text format and dumps the result as JSON tostdout.Usage
Installing and building:
Running:
Running with TLS client authentication:
Running without TLS validation (insecure, do not use in production!):
Advanced HTTP through
curl:This will dump the JSON to
stdout. Note that the dumped JSON is not using the deprecated JSON format as specified in the Prometheus exposition format reference. The created JSON uses a format much closer in structure to the protocol buffer format. It is only used by theprom2jsontool and has no significance elsewhere. See below for a description.A typical use-case is to pipe the JSON format into a tool like
jqto run a query over it. That looked like the following when the clients still supported the deprecated JSON format:Now simply use
prom2jsoninstead ofcurl(and change the query syntax according to the changed JSON format generated byprom2json):Example query to retrieve the number of metrics in the
http_requests_totalmetric family (only works with the new format):Example input from stdin:
JSON format
Note that all numbers are encoded as strings. Some parsers want it that way. Also, Prometheus allows sample values like
NaNor+Inf, which cannot be encoded as JSON numbers.A histogram is formatted as a native histogram if it has at least one span. It is then formatted in a similar way as the Prometheus query API does it.
Using Docker
You can deploy this tool using the prom/prom2json Docker image.
For example: