prom2json-se
v0.6.0
Published
[![npm][npm-badge]][npm-url]
Downloads
22
Maintainers
Readme
Prom2Json SE
Description
This small module is helping with conversion between Prometheus string output and JSON. JSON format is not standard output for Prometheus, but some processors prefer to use that one over any other.
Some snippets are inspired by https://github.com/anasceym/prom2json-stream
Installation
// If you use npm
npm i prom2json-se -S
// If you use yarn
yarn add prom2json-se
How to use
// Load module
const prom2Json = require('./');
// Use module
const promString = `
...
`;
const promJson = prom2Json.convert(promString);
Simple example with Prometheus client:
const express = require('express');
const app = express();
...
const Prometheus = require('prom-client');
const prom2Json = require('prom2json-se');
// Default Metrics (every 10s)
Prometheus.collectDefaultMetrics();
// Add metrics endpoint
app.use('/metrics-json', (req, res) => {
const json = prom2Json.convert(Prometheus.register.metrics());
res.send(json);
});
...
app.listen(process.env.PORT || 3000);
License
This module has MIT license.