jochen-schweizer / express-prom-bundle

express middleware with standard prometheus metrics in one bundle
MIT License
310 stars 68 forks source link

Adding prefix to "up" metric #121

Closed gandazgul closed 10 months ago

gandazgul commented 1 year ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch express-prom-bundle@6.6.0 for the project I'm working on.

When specifying a prefix through options.promClient.collectDefaultMetrics.prefix, all metrics are prefixed except for up. This fixes that.

Here is the diff that solved my problem:

diff --git a/node_modules/express-prom-bundle/src/index.js b/node_modules/express-prom-bundle/src/index.js
index 0c96dfb..55005d7 100644
--- a/node_modules/express-prom-bundle/src/index.js
+++ b/node_modules/express-prom-bundle/src/index.js
@@ -132,8 +132,9 @@ function main(opts) {
   };

   if (opts.includeUp !== false) {
+    const prefix = opts.promClient?.collectDefaultMetrics?.prefix || '';
     metrics.up = new promClient.Gauge({
-      name: 'up',
+      name: `${prefix}up`,
       help: '1 = up, 0 = not up',
       registers: [opts.promRegistry]
     });

This issue body was partially generated by patch-package.

gandazgul commented 1 year ago

Happy to submit a PR if this is desired.

pvoisin commented 11 months ago

Any chance we get that merged? :)

disjunction commented 10 months ago

Merged manually. Thanks for contributing. This was released in v7.0.0