feat: add upMetricName params to allow for up metric name customization

This commit is contained in:
Félix MARQUET
2025-04-25 06:47:26 +00:00
parent f9a0a7622a
commit db8710d5d0
4 changed files with 5 additions and 2 deletions

View File

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

2
package-lock.json generated
View File

@@ -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",

View File

@@ -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]
});

1
types/index.d.ts vendored
View File

@@ -38,6 +38,7 @@ declare namespace express_prom_bundle {
metricsPath?: string;
httpDurationMetricName?: string;
upMetricName?: string;
promClient?: { collectDefaultMetrics?: DefaultMetricsCollectorConfiguration<RegistryContentType> };
promRegistry?: Registry;
normalizePath?: NormalizePathEntry[] | NormalizePathFn;