@springtree/springboard-metrics
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i @springtree/springboard-metrics

Weekly Downloads

10

Version

1.2.0

License

ISC

Unpacked Size

70.9 kB

Total Files

38

Last publish

Collaborators

  • mdoeswijk
  • janvandenberg
  • adebree
  • appie
  • springtree_solutions