Add metricsApp option

Lets you supply an additional express app on which to mount the metrics 
endpoint
This commit is contained in:
Asbjørn Dyhrberg Thegler
2022-06-17 13:41:36 +02:00
parent 5e5a47a500
commit c4be86b651

View File

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