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 * **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 * **metricType**: histogram/summary selection. See more details below
* **httpDurationMetricName**: Allows you change the name of HTTP duration metric, default: **`http_request_duration_seconds`**. * **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 ### ### metricType option ###

2
package-lock.json generated
View File

@@ -6,7 +6,7 @@
"packages": { "packages": {
"": { "": {
"name": "express-prom-bundle", "name": "express-prom-bundle",
"version": "7.0.2", "version": "8.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@types/express": "^5.0.0", "@types/express": "^5.0.0",

View File

@@ -91,6 +91,7 @@ function main(opts) {
} }
const httpMetricName = opts.httpDurationMetricName || 'http_request_duration_seconds'; const httpMetricName = opts.httpDurationMetricName || 'http_request_duration_seconds';
const upMetricName = opts.upMetricName || 'up';
function makeHttpMetric() { function makeHttpMetric() {
const labels = ['status_code']; const labels = ['status_code'];
@@ -138,7 +139,7 @@ function main(opts) {
prefix = opts.promClient.collectDefaultMetrics.prefix || ''; prefix = opts.promClient.collectDefaultMetrics.prefix || '';
} }
metrics.up = new promClient.Gauge({ metrics.up = new promClient.Gauge({
name: `${prefix}up`, name: prefix + upMetricName,
help: '1 = up, 0 = not up', help: '1 = up, 0 = not up',
registers: [opts.promRegistry] registers: [opts.promRegistry]
}); });

1
types/index.d.ts vendored
View File

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