{"id":13463831,"url":"https://github.com/prometheus/prom2json","last_synced_at":"2025-03-25T09:31:06.998Z","repository":{"id":18293369,"uuid":"21465618","full_name":"prometheus/prom2json","owner":"prometheus","description":"A tool to scrape a Prometheus client and dump the result as JSON.","archived":false,"fork":false,"pushed_at":"2024-10-22T14:39:05.000Z","size":3233,"stargazers_count":372,"open_issues_count":0,"forks_count":90,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-10-29T16:21:39.320Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prometheus.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-07-03T14:33:07.000Z","updated_at":"2024-10-22T14:39:28.000Z","dependencies_parsed_at":"2024-02-13T20:25:33.794Z","dependency_job_id":"3072600b-ecde-4e67-a0e8-0bd98d97f1f7","html_url":"https://github.com/prometheus/prom2json","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prometheus%2Fprom2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prometheus%2Fprom2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prometheus%2Fprom2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prometheus%2Fprom2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prometheus","download_url":"https://codeload.github.com/prometheus/prom2json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245435098,"owners_count":20614827,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T14:00:29.084Z","updated_at":"2025-03-25T09:31:06.342Z","avatar_url":"https://github.com/prometheus.png","language":"Go","readme":"prom2json\n=========\n\nA tool to scrape a Prometheus client and dump the result as JSON.\n\n# Background\n\n(Pre-)historically, Prometheus clients were able to expose metrics as\nJSON. For various reasons, the JSON exposition format was deprecated.\n\nUsually, scraping of a Prometheus client is done by the Prometheus\nserver, which preferably happens with the protocol buffer\nformat. Sometimes, a human being needs to inspect what a Prometheus\nclients exposes. In that case, the text format is used (which is\notherwise meant to allow simplistic _clients_ like shell scripts to\nexpose metrics to a Prometheus _server_).\n\nHowever, some users wish to scrape Prometheus clients with programs\nother than the Prometheus server. Those programs would usually use the\nprotocol buffer format, but for small _ad hoc_ programs, that is too\nmuch of an (programming) overhead. JSON comes in handy for these\nuse-cases, as many languages offer tooling for JSON parsing.\n\nTo avoid maintaining a JSON format in all client libraries, the\n`prom2json` tool has been created, which scrapes a Prometheus client\nin protocol buffer or text format and dumps the result as JSON to\n`stdout`.\n\n# Usage\n\nInstalling and building:\n\n    $ GO111MODULE=on go install github.com/prometheus/prom2json/cmd/prom2json@latest\n\nRunning:\n\n    $ prom2json http://my-prometheus-client.example.org:8080/metrics\n    $ curl http://my-prometheus-client.example.org:8080/metrics | prom2json\n    $ prom2json /tmp/metrics.prom\n    \nRunning with TLS client authentication:\n\n    $ prom2json --cert=/path/to/certificate --key=/path/to/key http://my-prometheus-client.example.org:8080/metrics\n    \nRunning without TLS validation (insecure, do not use in production!):\n\n    $ prom2json --accept-invalid-cert https://my-prometheus-client.example.org:8080/metrics\n    \nAdvanced HTTP through `curl`:\n\n    $ curl -XPOST -H 'X-CSRFToken: 1234567890abcdef' --connect-timeout 60 'https://username:password@my-prometheus-client.example.org:8080/metrics' | prom2json\n\nThis will dump the JSON to `stdout`. Note that the dumped JSON is\n_not_ using the deprecated JSON format as specified in the\n[Prometheus exposition format\nreference](https://docs.google.com/document/d/1ZjyKiKxZV83VI9ZKAXRGKaUKK2BIWCT7oiGBKDBpjEY/edit?usp=sharing). The\ncreated JSON uses a format much closer in structure to the protocol\nbuffer format. It is only used by the `prom2json` tool and has no\nsignificance elsewhere. See below for a description.\n\nA typical use-case is to pipe the JSON format into a tool like `jq` to\nrun a query over it. That looked like the following when the clients\nstill supported the deprecated JSON format:\n\n    $ curl http://my-prometheus-client.example.org:8080/metrics | jq .\n\nNow simply use `prom2json` instead of `curl` (and change the query\nsyntax according to the changed JSON format generated by `prom2json`):\n\n    $ prom2json http://my-prometheus-client.example.org:8080/metrics | jq .\n\nExample query to retrieve the number of metrics in the `http_requests_total` metric family (only works with the new format):\n\n    $ prom2json http://my-prometheus-client.example.org:8080/metrics | jq '.[]|select(.name==\"http_requests_total\")|.metrics|length'\n\nExample input from stdin:\n\n    $ curl http://my-prometheus-client.example.org:8080/metrics | grep http_requests_total | prom2json\n\n# JSON format\n\nNote that all numbers are encoded as strings. Some parsers want it\nthat way. Also, Prometheus allows sample values like `NaN` or `+Inf`,\nwhich cannot be encoded as JSON numbers.\n\nA histogram is formatted as a native histogram if it has at least one span. It\nis then formatted in a similar way as [the Prometehus query\nAPI](https://prometheus.io/docs/prometheus/latest/querying/api/#native-histograms)\ndoes it.\n\n```json\n[\n  {\n    \"name\": \"http_request_duration_microseconds\",\n    \"help\": \"The HTTP request latencies in microseconds.\",\n    \"type\": \"SUMMARY\",\n    \"metrics\": [\n      {\n        \"labels\": {\n          \"method\": \"get\",\n          \"handler\": \"prometheus\",\n          \"code\": \"200\"\n        },\n        \"quantiles\": {\n          \"0.99\": \"67542.292\",\n          \"0.9\": \"23902.678\",\n          \"0.5\": \"6865.718\"\n        },\n        \"count\": \"743\",\n        \"sum\": \"6936936.447000001\"\n      },\n      {\n        \"labels\": {\n          \"method\": \"get\",\n          \"handler\": \"prometheus\",\n          \"code\": \"400\"\n        },\n        \"quantiles\": {\n          \"0.99\": \"3542.9\",\n          \"0.9\": \"1202.3\",\n          \"0.5\": \"1002.8\"\n        },\n        \"count\": \"4\",\n        \"sum\": \"345.01\"\n      }\n    ]\n  },\n  {\n    \"name\": \"roshi_select_call_count\",\n    \"help\": \"How many select calls have been made.\",\n    \"type\": \"COUNTER\",\n    \"metrics\": [\n      {\n        \"value\": \"1063110\"\n      }\n    ]\n  },\n  {\n    \"name\": \"http_request_duration_seconds\",\n    \"type\": \"HISTOGRAM\",\n    \"help\": \"This is a native histogram.\",\n    \"metrics\": [\n      {\n        \"labels\": {\n        \"method\": \"GET\",\n        },\n        \"buckets\": [\n          [\n            0,\n            \"17.448123722644123\",\n            \"19.027313840043536\",\n            \"139\"\n          ],\n          [\n            0,\n            \"19.027313840043536\",\n            \"20.749432874416154\",\n            \"85\"\n          ],\n          [\n            0,\n            \"20.749432874416154\",\n            \"22.62741699796952\",\n            \"70\"\n          ],\n        ],\n        \"count\": \"1000\",\n        \"sum\": \"29969.50000000001\"\n      }\n    ]\n  },\n  {\n    \"name\": \"some_weird_normal_distribution\",\n    \"type\": \"HISTOGRAM\",\n    \"help\": \"This is a classic histogram.\",\n    \"metrics\": [\n      {\n        \"buckets\": {\n          \"-0.0001899999999999998\": \"17\",\n          \"-0.0002899999999999998\": \"6\",\n          \"-0.0003899999999999998\": \"2\",\n          \"-0.0004899999999999998\": \"2\",\n          \"-0.0005899999999999998\": \"0\",\n          \"-0.0006899999999999999\": \"0\",\n          \"-0.0007899999999999999\": \"0\",\n          \"-0.00089\": \"0\",\n          \"-0.00099\": \"0\",\n          \"-8.999999999999979e-05\": \"33\",\n          \"0.00011000000000000022\": \"75\",\n          \"0.00021000000000000023\": \"92\",\n          \"0.0003100000000000002\": \"100\",\n          \"0.0004100000000000002\": \"103\",\n          \"0.0005100000000000003\": \"105\",\n          \"0.0006100000000000003\": \"106\",\n          \"0.0007100000000000003\": \"107\",\n          \"0.0008100000000000004\": \"107\",\n          \"0.0009100000000000004\": \"107\",\n          \"1.0000000000000216e-05\": \"50\"\n        },\n        \"count\": \"107\",\n        \"sum\": \"0.001792103516591124\"\n      }\n    ]\n  }\n]\n```\n\n## Using Docker\n\nYou can deploy this tool using the [prom/prom2json](https://registry.hub.docker.com/r/prom/prom2json/) Docker image.\n\nFor example:\n\n```bash\ndocker pull prom/prom2json\n\ndocker run --rm -ti prom/prom2json http://my-prometheus-client.example.org:8080/metrics\n```\n","funding_links":[],"categories":["Performance","Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprometheus%2Fprom2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprometheus%2Fprom2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprometheus%2Fprom2json/lists"}