This module allow you to simply expose Node.js metrics, can expose route status code metrics and give an easy way of expose metrics.
This module is based on the siimon/prom-client module.
To activate the metrics, you must call the initPrometheus method. This method require an
express application:
const express = require('express');
const { initPrometheus } = require('wed-config-nodejs-prometheus');
const app = express();
initPrometheus(app);By doing it, all routes status codes will be gathered with the default Node.js ones.
You can disable routes status codes or default Node.js ones by passing some options on the initialization :
initPrometheus(app, {
collectDefaultMetrics: false,
addRouteMetrics: false,
});Three metrics are currently available and exposed on the same package:
- Counter via the
getCountermethod, - Gauge via the
getGaugemethod, - Histogram via the
getHistogrammethod, - Summary via the
getSummarymethod.
Every getter need a name, the name will automatically be cleaned and snake_case formatted to fit the Prometheus requirements.
const { getCounter, getHistogram, getSummary } = require('wed-config-nodejs-prometheus');
const myCounter = getCounter("This is my counter");
myCounter.inc();