@duytbp/express-prometheus-route-metrics
v1.0.2
Published
Express middleware for collecting route metrics using prom-client.
Maintainers
Readme
@duytbp/express-prometheus-route-metrics
Express middleware for collecting route metrics using prom-client. Exports Prometheus-compatible metrics for HTTP request durations, labeled by method, status code, and route path.
Features
- Collects request duration histograms for each route
- Exposes metrics at a configurable endpoint (default:
/metrics) - Customizable histogram buckets and metric names
Installation
npm install @duytbp/express-prometheus-route-metrics prom-clientUsage
const express = require("express");
const routeMetrics = require("@duytbp/express-prometheus-route-metrics");
const app = express();
// Add the metrics middleware before your routes
app.use(
routeMetrics({
// Optional configuration:
// metricName: "http_request_duration_seconds",
// metricsPath: "/metrics",
// buckets: [0.05, 0.1, 0.25, 0.5, 0.75, 1, 2.5, 5],
// unknownPathName: "[UNKNOWN]",
}),
);
// Define your routes as usual
app.get("/hello", (req, res) => {
res.send("Hello, world!");
});
// Start your server
app.listen(3000, () => {
console.log("Server listening on port 3000");
});This will expose Prometheus metrics at /metrics by default.
