1.2.0 • Published 1 year ago

@springtree/springboard-metrics v1.2.0

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

springboard-metrics

Expose metrics in Prometheus format on a Node.JS API with custom Express middleware.

Features

Dependencies

Installation

Install the package using NPM

npm i @springtree/springboard-metrics

Using the package

Import the package

import { prometheusMiddleware } from '@springtree/springboard-metrics';

Initialize Express API

this.app = express();

Make the Express API use the middleware

this.app.use(prometheusMiddleware('API_name', 'API_version_0.1', {defaultMetricsPath: '/metrics'}));

Expose the metrics

Import prom-client

const prometheus = require('prom-client')

Make an endpoint to expose the metrics

app.get('/metrics', (async (request, response) => { response.send(await prometheus.register.metrics()); }));

Navigate to '/metrics' to see the exposed metrics in Prometheus format.

Ignoring the /metrics path

Make sure the endpoint path and the 'defaultMetricsPath' in the options are the same.

If you don't do this, the Prometheus instance that scrapes '/metrics' will count as a request.

A Prometheus instance scrapes at a set interval, this means that the metrics will increase over time without user action.

Prometheus target

The '/metrics' endpoint is also the target for a Prometheus Instance to scrape.