prom2json-stream
is a NodeJS stream transformer to parse Prometheus exporters' metrics into JSON
Example
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.787184e+06
# HELP promhttp_metric_handler_requests_total Total number of scrapes by HTTP status code.
# TYPE promhttp_metric_handler_requests_total counter
promhttp_metric_handler_requests_total{code="200"} 139170
promhttp_metric_handler_requests_total{code="500"} 0
promhttp_metric_handler_requests_total{code="503"} 0
transformed into
Installation
Using NPM
npm install prom2json-stream
Usage
From a readable stream
var Prom2Json = var split = var buffer = `# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.# TYPE go_memstats_alloc_bytes gaugego_memstats_alloc_bytes 2.787184e+06`var stream = streamstream stream // {// "help": "Number of bytes allocated and still in use.",// "name": "go_memstats_alloc_bytes",// "type": "gauge",// "value": 2787184// }
Caveats
This library only accepting string/buffer that has been splitted by newline. Please consider using any working splitter (eg: binary-split