prom2json-se

0.6.0 • Public • Published

Prom2Json SE

npm

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.

Package Sidebar

Install

npm i prom2json-se

Weekly Downloads

23

Version

0.6.0

License

MIT

Unpacked Size

4.92 kB

Total Files

7

Last publish

Collaborators

  • michaelortho