From c4be86b6514219b60caa5cf271efac0ea103567d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Dyhrberg=20Thegler?= Date: Fri, 17 Jun 2022 13:41:36 +0200 Subject: [PATCH] Add metricsApp option Lets you supply an additional express app on which to mount the metrics endpoint --- src/index.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 6f85193..cc6969e 100644 --- a/src/index.js +++ b/src/index.js @@ -68,7 +68,8 @@ function main(opts) { formatStatusCode: main.normalizeStatusCode, metricType: 'histogram', promClient: {}, - promRegistry: promClient.register + promRegistry: promClient.register, + metricsApp: null, }, opts ); @@ -204,6 +205,13 @@ function main(opts) { next(); }; + if (opts.metricsApp) { + opts.metricsApp.get(opts.metricsPath || '/metrics', async (req, res, next) => { + res.set('Content-Type', opts.promRegistry.contentType); + return res.end(await opts.promRegistry.metrics()); + }); + } + middleware.metrics = metrics; middleware.promClient = promClient; middleware.metricsMiddleware = metricsMiddleware;