ability to exclude incoming request from metrics

This commit is contained in:
yacine
2020-11-28 21:42:52 +01:00
parent c55d5f4862
commit 52fdbf030f
3 changed files with 7 additions and 1 deletions

View File

@@ -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 ###

View File

@@ -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
View File

@@ -28,6 +28,8 @@ declare namespace express_prom_bundle {
includePath?: boolean;
includeUp?: boolean;
filter?: (req: Request) => boolean;
metricType?: 'summary' | 'histogram';
metricsPath?: string;
httpDurationMetricName?: string;