mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-01-18 16:27:28 +01:00
ability to exclude incoming request from metrics
This commit is contained in:
@@ -52,7 +52,7 @@ Which labels to include in `http_request_duration_seconds` metric:
|
||||
* **includeUp**: include an auxiliary "up"-metric which always returns 1, default: **true**
|
||||
* **metricsPath**: replace the `/metrics` route with a **regex** or exact **string**. Note: it is highly recommended to just stick to the default
|
||||
* **metricType**: histogram/summary selection. See more details below
|
||||
|
||||
* **filter**: whether the incoming request should be included in the metrics
|
||||
|
||||
### metricType option ###
|
||||
|
||||
|
||||
@@ -131,6 +131,10 @@ function main(opts) {
|
||||
: new RegExp('^' + (opts.metricsPath || '/metrics') + '/?$');
|
||||
|
||||
const middleware = function (req, res, next) {
|
||||
if (opts.filter && opts.filter(req)) {
|
||||
return next();
|
||||
}
|
||||
|
||||
const path = req.originalUrl || req.url; // originalUrl gets lost in koa-connect?
|
||||
|
||||
if (opts.autoregister && path.match(metricsMatch)) {
|
||||
|
||||
2
types/index.d.ts
vendored
2
types/index.d.ts
vendored
@@ -28,6 +28,8 @@ declare namespace express_prom_bundle {
|
||||
includePath?: boolean;
|
||||
includeUp?: boolean;
|
||||
|
||||
filter?: (req: Request) => boolean;
|
||||
|
||||
metricType?: 'summary' | 'histogram';
|
||||
metricsPath?: string;
|
||||
httpDurationMetricName?: string;
|
||||
|
||||
Reference in New Issue
Block a user