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
getCounter
method, - Gauge via the
getGauge
method, - Histogram via the
getHistogram
method, - Summary via the
getSummary
method.
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();