@osrs-tracker/express-metrics
v0.2.0
Published
Prometheus HTTP metrics for the OSRS Tracker Express apps, on @prometheus-io/client
Readme
@osrs-tracker/express-metrics ·

Prometheus HTTP metrics for the Express 5 apps of OSRS Tracker, on
@prometheus-io/client (the successor of prom-client). It
replaces express-prom-bundle and keeps its series unchanged:
http_request_duration_seconds: a histogram with labelsstatus_code,methodandpath, and buckets0.003, 0.03, 0.1, 0.3, 1.5, 10. A request the client closed before the response was sent gets status499.up: a gauge set to1.- Node process metrics (event-loop lag, heap, GC, handles), unless
defaultMetrics: false.
Install
npm install @osrs-tracker/express-metricsUsage
import express from 'express';
import { metricsMiddleware } from '@osrs-tracker/express-metrics';
const app = express();
const metricsApp = express(); // served on a separate port
app.use(metricsMiddleware({ metricsApp, normalizePath: (req, res) => req.route?.path ?? 'unknown' }));
app.listen(8080);
metricsApp.listen(9100); // GET /metricsOptions: metricsPath (default /metrics), registry (default the global register, cleared first so hot reloads
don't register the metrics twice) and defaultMetrics (default true). Keep normalizePath low-cardinality: route
patterns, not usernames or IDs.
The package re-exports register, Registry, Counter and Gauge, so an app can add its own metrics to the same
registry. Create them after metricsMiddleware, which clears the registry.
