express-prom-bundle-nwt
v1.1.6
Published
express middleware with popular prometheus metrics in one bundle
Downloads
2
Maintainers
Readme
express prometheus bundle
express middleware with popular prometheus metrics in one bundle.
Internally it uses prom-client. See: https://github.com/siimon/prom-client
Included metrics:
up
: normally is just 1nodejs_memory_heap_total_bytes
andnodejs_memory_heap_used_bytes
http_request_seconds
: http latency histogram labeled withstatus_code
Install
npm install express-prom-bundle
Usage
const promBundle = require("express-prom-bundle"),
const metricsMiddleware = promBundle({/* options */ });
app.use(metricsMiddleware);
app.use(/* your middleware */);
app.listen(3000);
- call your endpoints
- see your metrics here: http://localhost:3000/metrics
ALERT!
The order in wich the routes are registered is important, since only the routes registered after the express-prom-bundle will be measured
You can use this to your advantage to bypass some of the routes. See the example below.
Options
- prefix: prefix added to every metric name
- whitelist, blacklist: array of strings or regexp specifying which metrics to include/exclude
- buckets: buckets used for
http_request_seconds
histogram - excludeRoutes: array of strings or regexp specifying which routes should be skipped for
http_request_seconds
metric. It usesreq.path
as subject when checking
Example
setup std. metrics but exclude up
-metric:
"use strict";
const express = require("express"),
app = express(),
promBundle = require("express-prom-bundle");
// calls to this route will not appear in metrics
// because it's applied before promBundle
app.get("/status", (req, res) => res.send("i am healthy"));
app.use(promBundle({
prefix: "demo_app:something",
excludeRoutes: ["/foo"]
}));
// this call will NOT appear in metrics, because it matches excludeRoutes
app.get("/foo", (req, res) => res.send("bar"));
// calls to this route will appear in metrics
app.get("/hello", (req, res) => res.send("ok"));
app.listen(3000);
See an advanced example on github
License
MIT