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;