Parses Prometheus text format into JavaScript objects
npm install prometheus-text-to-jsonparse-prometheus-text-format
==
A module that parses the Prometheus text format. The output aims to be compatible with that of prom2json. The code for parsing individual samples was ported from the Prometheus Python Client.
Installation
==
```
npm install --save parse-prometheus-text-format
Usage
==
`js
import fs from 'fs';
import parsePrometheusTextFormat from 'parse-prometheus-text-format';
const metricsStr = fs.readFileSync('metrics.txt', 'utf8');
const parsed = parsePrometheusTextFormat(metricsStr);
`
Example
==
Input:
`HELP jvm_classes_loaded The number of classes that are currently loaded in the JVM
TYPE jvm_classes_loaded gauge
jvm_classes_loaded 3851.0
Stringified result:
`js
[
{
"name": "jvm_classes_loaded",
"help": "The number of classes that are currently loaded in the JVM",
"type": "GAUGE",
"metrics": [
{
"value": "3851.0"
}
]
},
{
"name": "http_requests_total",
"help": "The total number of HTTP requests.",
"type": "COUNTER",
"metrics": [
{
"value": "1027",
"labels": {
"method": "post",
"code": "200"
}
},
{
"value": "3",
"labels": {
"method": "post",
"code": "400"
}
}
]
},
{
"name": "msdos_file_access_time_seconds",
"help": "",
"type": "UNTYPED",
"metrics": [
{
"value": "1.458255915e9",
"labels": {
"path": "C:\\DIR\\FILE.TXT",
"error": "Cannot find file:\n\"FILE.TXT\""
}
}
]
},
{
"name": "metric_without_timestamp_and_labels",
"help": "",
"type": "UNTYPED",
"metrics": [
{
"value": "12.47"
}
]
},
{
"name": "something_weird",
"help": "",
"type": "UNTYPED",
"metrics": [
{
"value": "+Inf",
"labels": {
"problem": "division by zero"
}
}
]
},
{
"name": "http_request_duration_seconds",
"help": "A histogram of the request duration.",
"type": "HISTOGRAM",
"metrics": [
{
"buckets": {
"1": "133988",
"0.05": "24054",
"0.1": "33444",
"0.2": "100392",
"0.5": "129389",
"+Inf": "144320"
},
"count": "144320",
"sum": "53423"
}
]
},
{
"name": "rpc_duration_seconds",
"help": "A summary of the RPC duration in seconds.",
"type": "SUMMARY",
"metrics": [
{
"quantiles": {
"0.01": "3102",
"0.05": "3272",
"0.5": "4773",
"0.9": "9001",
"0.99": "76656"
},
"count": "2693",
"sum": "1.7560473e+07"
}
]
},
{
"name": "jvm_gc_collection_seconds",
"help": "Time spent in a given JVM garbage collector in seconds.",
"type": "SUMMARY",
"metrics": [
{
"labels": {
"gc": "Copy"
},
"count": "104.0",
"sum": "0.491"
},
{
"labels": {
"gc": "MarkSweepCompact"
},
"count": "12.0",
"sum": "0.486"
}
]
}
]
``