2.0.7 • Published 1 year ago

@tailorbrands/node-exporter-prometheus v2.0.7

Weekly downloads
306
License
MIT
Repository
github
Last release
1 year ago

CircleCI Test Coverage Maintainability

Prometheus Exporter for Express Applications

This module allows application to expose Prometheus compatible metrics. The metrics include request duration and statuses and optionally those that are exported by default in prom-client. Example output showing all metrics. By default, the /metrics and /healthz endpoints are ignored.

Installing

npm install @tailorbrands/node-exporter-prometheus

Setup

Since the duration of requests is being measured, it is important that the exporter be activated before the first application route or middleware.

app = express();
// Node prometheus exporter setup
const options = {appName}; // `appName` is the name of your service/application
const prometheusExporter = require('@tailorbrands/node-exporter-prometheus')
const promExporter = PromExporter(options);
app.use(promExporter.middleware);
app.get('/metrics', promExporter.metrics);
// Application routes and middleware starts here
app.use(...)
app.get(...)
app.post(...)

Options

  • appName - Name that will be used in the label for every metric
  • ignoredRoutes (optional) - An array of routes to be exuded when calculating metrics. Default value: ['/metrics', '/healthz']
  • collectDefaultMetrics (optional) - A boolean indicating whether or not to collect default nodejs metrics (default: false)

Additional Metrics

Once you have the default metrics accessible, you might want to add some of your own custom metrics. The module exposes the underlying prom-client as a property called client. This allows you to add any other prom-client metrics. Here is an example using a Gauge metric. It will add something similar to following in the output of the metrics endpoint:

const {promMiddleware, promMetrics, promClient} = require('node-prometheus-exporter')({ appName });
const simpleCounter = new promClient.Gauge({
  name: 'simple_counter',
  help: 'One route increases another one decreases'
});
app.get('/increase', (req, res) => {
  simpleCounter.inc()
  res.send(200)
})
app.get('/decrease', (req, res) => {
  simpleCounter.dec()
  res.send(200)
})

Testing

npm test

About Tailor Brands

Check us out!

2.0.7

1 year ago

2.0.5

2 years ago

2.0.6

2 years ago

2.0.4

2 years ago

2.0.3

2 years ago

2.0.2

2 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago