From db8710d5d0ed9d2868aa23293c0ad769bbdb9900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20MARQUET?= <72651575+BreizhHardware@users.noreply.github.com> Date: Fri, 25 Apr 2025 06:47:26 +0000 Subject: [PATCH] feat: add upMetricName params to allow for up metric name customization --- README.md | 1 + package-lock.json | 2 +- src/index.js | 3 ++- types/index.d.ts | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 24226f4..127c384 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Which labels to include in `http_request_duration_seconds` metric: * **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 * **httpDurationMetricName**: Allows you change the name of HTTP duration metric, default: **`http_request_duration_seconds`**. +* **upMetricName**: Allows you change the name of up metric, default: **`up`**. ### metricType option ### diff --git a/package-lock.json b/package-lock.json index 77c166e..8b25012 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6,7 +6,7 @@ "packages": { "": { "name": "express-prom-bundle", - "version": "7.0.2", + "version": "8.0.0", "license": "MIT", "dependencies": { "@types/express": "^5.0.0", diff --git a/src/index.js b/src/index.js index 5cf81d0..3e114c2 100644 --- a/src/index.js +++ b/src/index.js @@ -91,6 +91,7 @@ function main(opts) { } const httpMetricName = opts.httpDurationMetricName || 'http_request_duration_seconds'; + const upMetricName = opts.upMetricName || 'up'; function makeHttpMetric() { const labels = ['status_code']; @@ -138,7 +139,7 @@ function main(opts) { prefix = opts.promClient.collectDefaultMetrics.prefix || ''; } metrics.up = new promClient.Gauge({ - name: `${prefix}up`, + name: prefix + upMetricName, help: '1 = up, 0 = not up', registers: [opts.promRegistry] }); diff --git a/types/index.d.ts b/types/index.d.ts index af88a47..999d221 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -38,6 +38,7 @@ declare namespace express_prom_bundle { metricsPath?: string; httpDurationMetricName?: string; + upMetricName?: string; promClient?: { collectDefaultMetrics?: DefaultMetricsCollectorConfiguration }; promRegistry?: Registry; normalizePath?: NormalizePathEntry[] | NormalizePathFn;