Prometheus metrics
Turn JSON metrics into the Prometheus text format and read such text back into JSON. Typical uses: expose a /metrics page, read the metrics of another service.
prometheus format <json_metrics>
Description
JSON metrics to the text format 0.0.4
JSON metrics to the text format 0.0.4
Parameters
json_metrics: The metrics: a JSON array of {name, type, help, unit, samples} (or one object) - String - required
json_metrics: The metrics: a JSON array of {name, type, help, unit, samples} (or one object) - String - required
admin
prometheus format "[{\"name\": \"http_requests_total\", \"type\": \"counter\", \"help\": \"HTTP requests.\", \"samples\": [{\"labels\": {\"method\": \"get\", \"code\": \"200\"}, \"value\": 1027}, {\"labels\": {\"method\": \"post\", \"code\": \"500\"}, \"value\": 3}]}, {\"name\": \"queue_size\", \"type\": \"gauge\", \"help\": \"Messages waiting.\", \"value\": 12}]"
mentdb
# HELP http_requests_total HTTP requests. # TYPE http_requests_total counter http_requests_total{method="get",code="200"} 1027 http_requests_total{method="post",code="500"} 3 # HELP queue_size Messages waiting. # TYPE queue_size gauge queue_size 12
A histogram and a summary
admin
prometheus format "[{\"name\": \"rpc_duration_seconds\", \"type\": \"histogram\", \"help\": \"RPC time.\", \"samples\": [{\"labels\": {\"service\": \"auth\"}, \"buckets\": {\"0.05\": 24, \"0.1\": 33, \"0.5\": 100, \"+Inf\": 102}, \"sum\": 8.4}]}, {\"name\": \"job_seconds\", \"type\": \"summary\", \"samples\": [{\"quantiles\": {\"0.5\": 0.25, \"0.99\": 1.8}, \"sum\": 41.5, \"count\": 120}]}]"
mentdb
# HELP rpc_duration_seconds RPC time. # TYPE rpc_duration_seconds histogram rpc_duration_seconds_bucket{service="auth",le="0.05"} 24 rpc_duration_seconds_bucket{service="auth",le="0.1"} 33 rpc_duration_seconds_bucket{service="auth",le="0.5"} 100 rpc_duration_seconds_bucket{service="auth",le="+Inf"} 102 rpc_duration_seconds_count{service="auth"} 102 rpc_duration_seconds_sum{service="auth"} 8.4 # TYPE job_seconds summary job_seconds{quantile="0.5"} 0.25 job_seconds{quantile="0.99"} 1.8 job_seconds_count 120 job_seconds_sum 41.5
One sample with a timestamp, and NaN
admin
prometheus format "[{\"name\": \"temperature_celsius\", \"type\": \"gauge\", \"labels\": {\"room\": \"lab 1\"}, \"value\": 21.5, \"timestamp\": 1730800000000}, {\"name\": \"ratio\", \"type\": \"gauge\", \"value\": \"NaN\"}]"
mentdb
# TYPE temperature_celsius gauge temperature_celsius{room="lab 1"} 21.5 1730800000000 # TYPE ratio gauge ratio NaN
A bucket that goes down: refused
admin
prometheus format "[{\"name\": \"h\", \"type\": \"histogram\", \"samples\": [{\"buckets\": {\"1\": 5, \"2\": 4, \"+Inf\": 6}}]}]"
mentdb
ERROR: Sorry, an error appears (the buckets of the sample 0 of the metric 'h' are cumulative: the count of the bucket 2.0 is lower than the one before).
prometheus format <json_metrics> <json_params>
Description
JSON metrics to text with parameters: format (0.0.4 or openmetrics)
JSON metrics to text with parameters: format (0.0.4 or openmetrics)
Parameters
json_metrics: The metrics: a JSON array of {name, type, help, unit, samples} (or one object) - String - required
json_params: The parameters - String - required
json_metrics: The metrics: a JSON array of {name, type, help, unit, samples} (or one object) - String - required
json_params: The parameters - String - required
admin
prometheus format "[{\"name\": \"http_requests_total\", \"type\": \"counter\", \"help\": \"HTTP requests.\", \"samples\": [{\"labels\": {\"method\": \"get\", \"code\": \"200\"}, \"value\": 1027}, {\"labels\": {\"method\": \"post\", \"code\": \"500\"}, \"value\": 3}]}, {\"name\": \"queue_size\", \"type\": \"gauge\", \"help\": \"Messages waiting.\", \"value\": 12}, {\"name\": \"temp_celsius\", \"type\": \"gauge\", \"unit\": \"celsius\", \"value\": 21.5, \"timestamp\": 1730800000123}]" "{\"format\": \"openmetrics\"}"
mentdb
# TYPE http_requests counter # HELP http_requests HTTP requests. http_requests_total{method="get",code="200"} 1027 http_requests_total{method="post",code="500"} 3 # TYPE queue_size gauge # HELP queue_size Messages waiting. queue_size 12 # TYPE temp_celsius gauge # UNIT temp_celsius celsius temp_celsius 21.5 1730800000.123 # EOF
info and stateset, only in OpenMetrics
admin
prometheus format "[{\"name\": \"build_info\", \"type\": \"info\", \"labels\": {\"version\": \"4.0.0\"}, \"value\": 1}, {\"name\": \"door\", \"type\": \"stateset\", \"samples\": [{\"labels\": {\"door\": \"open\"}, \"value\": 1}, {\"labels\": {\"door\": \"closed\"}, \"value\": 0}]}]" "{\"format\": \"openmetrics\"}"
mentdb
# TYPE build info build_info{version="4.0.0"} 1 # TYPE door stateset door{door="open"} 1 door{door="closed"} 0 # EOF
Used in use cases (1 recipe)
System administrator & DevOps › Publish the counters of an application as a Prometheus /metrics page
System administrator & DevOps › Publish the counters of an application as a Prometheus /metrics page
prometheus parse <text>
Description
The text of a /metrics page to JSON, in the shape that prometheus format takes
The text of a /metrics page to JSON, in the shape that prometheus format takes
Parameters
text: The text of a /metrics page - String - required
text: The text of a /metrics page - String - required
admin
prometheus parse "# HELP http_requests_total HTTP requests. # TYPE http_requests_total counter http_requests_total{method=\"get\",code=\"200\"} 1027 1730800000000 http_requests_total{method=\"post\",code=\"500\"} 3 1730800000000 # a free comment process_open_fds 17"
mentdb
[{"name": "http_requests_total", "type": "counter", "help": "HTTP requests.", "samples": [{"labels": {"method": "get", "code": "200"}, "value": 1027, "timestamp": 1730800000000}, {"labels": {"method": "post", "code": "500"}, "value": 3, "timestamp": 1730800000000}]}, {"name": "process_open_fds", "type": "untyped", "samples": [{"labels": {}, "value": 17}]}]
A histogram
admin
prometheus parse "# TYPE rpc_duration_seconds histogram rpc_duration_seconds_bucket{le=\"0.05\"} 24 rpc_duration_seconds_bucket{le=\"0.1\"} 33 rpc_duration_seconds_bucket{le=\"+Inf\"} 40 rpc_duration_seconds_sum 3.2 rpc_duration_seconds_count 40"
mentdb
[{"name": "rpc_duration_seconds", "type": "histogram", "samples": [{"labels": {}, "buckets": {"0.05": 24, "0.1": 33, "+Inf": 40}, "sum": 3.2, "count": 40}]}]
OpenMetrics: the exemplar and _created are left out
admin
prometheus parse "# TYPE http_requests counter # HELP http_requests HTTP requests. http_requests_total{code=\"200\"} 1027 1730800000.5 # {trace_id=\"a1\"} 1 http_requests_created{code=\"200\"} 1730700000 # TYPE build info build_info{version=\"4.0.0\"} 1 # EOF"
mentdb
[{"name": "http_requests_total", "type": "counter", "help": "HTTP requests.", "samples": [{"labels": {"code": "200"}, "value": 1027, "timestamp": 1730800000500}]}, {"name": "build_info", "type": "info", "samples": [{"labels": {"version": "4.0.0"}, "value": 1}]}]
A label that is not closed
admin
prometheus parse "up{job=\"api} 1"
mentdb
ERROR: Sorry, an error appears (line 1: the value of the label 'job' is not closed).
prometheus parse <text> <json_params>
Description
Text to JSON with parameters: format (auto, 0.0.4 or openmetrics; auto reads OpenMetrics when the text has # EOF), flat (false; true gives one row per line)
Text to JSON with parameters: format (auto, 0.0.4 or openmetrics; auto reads OpenMetrics when the text has # EOF), flat (false; true gives one row per line)
Parameters
text: The text of a /metrics page - String - required
json_params: The parameters - String - required
text: The text of a /metrics page - String - required
json_params: The parameters - String - required
admin
prometheus parse "# TYPE rpc_duration_seconds histogram rpc_duration_seconds_bucket{le=\"0.05\"} 24 rpc_duration_seconds_bucket{le=\"0.1\"} 33 rpc_duration_seconds_bucket{le=\"+Inf\"} 40 rpc_duration_seconds_sum 3.2 rpc_duration_seconds_count 40" "{\"flat\": true}"
mentdb
[{"metric": "rpc_duration_seconds_bucket", "family": "rpc_duration_seconds", "type": "histogram", "labels": {"le": "0.05"}, "value": 24}, {"metric": "rpc_duration_seconds_bucket", "family": "rpc_duration_seconds", "type": "histogram", "labels": {"le": "0.1"}, "value": 33}, {"metric": "rpc_duration_seconds_bucket", "family": "rpc_duration_seconds", "type": "histogram", "labels": {"le": "+Inf"}, "value": 40}, {"metric": "rpc_duration_seconds_sum", "family": "rpc_duration_seconds", "type": "histogram", "labels": {}, "value": 3.2}, {"metric": "rpc_duration_seconds_count", "family": "rpc_duration_seconds", "type": "histogram", "labels": {}, "value": 40}]
OpenMetrics needs # EOF
admin
prometheus parse "up 1" "{\"format\": \"openmetrics\"}"
mentdb
ERROR: Sorry, an error appears (the OpenMetrics text does not end with # EOF).
Used in use cases (2 recipes)
System administrator & DevOps › Publish the counters of an application as a Prometheus /metrics page
System administrator & DevOps › Read the disk space of a node exporter and draw the free space of each disk
System administrator & DevOps › Publish the counters of an application as a Prometheus /metrics page
System administrator & DevOps › Read the disk space of a node exporter and draw the free space of each disk
Often used with
chart svg · prometheus format · string char · string left · string length · string right
chart svg · prometheus format · string char · string left · string length · string right
