1.3.5 • Published 1 month ago

prometheus-middleware v1.3.5

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

GitHub release GitHub license CI pipeline Opened issues Opened PR Code coverage Node version

Node.js simple middleware to expose Prometheus metrics

Purpose

Module to create an HTTP server to expose Prometheus metrics.
By default it:

  • runs an HTTP server to expose metrics
  • instantiates and returns a prom-client
  • patches http server to get request response time
  • allows to define custom metrics through prom-client

Compatibility

Supported and tested : >= 14.0

VersionSupportedTested
16.xyesyes
18.xyesyes
20.xyesyes

It works with different HTTP servers:

By default you can access your metrics on this endpoint: http://localhost:9350/metrics

Installation

$ npm install prometheus-middleware --save

Usage

Basic

const APM = require('prometheus-middleware')
const apm = new APM()
apm.init()

Add a custom metric

const APM = require('prometheus-middleware')
const apm = new APM()
apm.init()
// ----------------
const counter = new apm.client.Counter({
  name: 'metric_name',
  help: 'metric_help',
})
// ----------------
counter.inc(); // Increment by 1
counter.inc(10); // Increment by 10

The metrics system is exactly the same as in prom-client librairy.

Configuration

The config is an JSON object which accepts the following property:

const APM = require('prometheus-middleware')
const apm = new APM({
  METRICS_ROUTE: "/metrics",
  PORT: 9350,
  PROM_CLIENT_CONF: {},
  HTTP_DURATION_BUCKETS: [0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2]
  HTTP_SUMMARY_PERCENTILES: [0.5, 0.9, 0.95, 0.99]
  NORMALIZE_ENDPOINT: false,
})
apm.init()

Destroy the APM

If you use a graceful exit method or if you want to simply stop the APM, you should run:

const APM = require('prometheus-middleware')
const apm = new APM()
apm.init()

process.on('SIGTERM', () => {
  apm.destroy()
})
PropertyDefaultDescription
METRICS_ROUTE/metricsRoute to expose the metrics
PORT9350Port to listen metrics
PROM_CLIENT_CONF{}Configuration of the prom-client lib
HTTP_DURATION_BUCKETS0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2List of values for HTTP request duration
HTTP_SUMMARY_PERCENTILES0.5, 0.9, 0.95, 0.99List of values for HTTP request percentiles
NORMALIZE_ENDPOINTtrueNormalize endpoint by occulting ids, and query parameters

To see how to use the module you can refer to the example folder.

Debug

The agent use debug module in order not to pollute your logs. If you want to see all agent output just use DEBUG environment variable:

DEBUG=prometheus-middleware* node myApp.js

Test

$ npm test

Coverage report can be found in coverage/.

1.3.5

1 month ago

1.3.4

2 months ago

1.3.3

4 months ago

1.3.2

5 months ago

1.3.1

5 months ago

1.3.0

5 months ago

1.2.0

6 months ago

1.1.4

8 months ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago