mirror of
https://github.com/BreizhHardware/express-prom-bundle.git
synced 2026-01-18 16:27:28 +01:00
Allows for customizing promRegistry when creating prom bundle.
This commit is contained in:
@@ -53,6 +53,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
|
||||
|
||||
|
||||
### metricType option ###
|
||||
|
||||
Two metric types are supported for `http_request_duration_seconds` metric:
|
||||
@@ -85,6 +86,7 @@ Additional options for **summary**:
|
||||
* **promClient**: options for promClient startup, e.g. **collectDefaultMetrics**. This option was added
|
||||
to keep `express-prom-bundle` runnable using confit (e.g. with kraken.js) without writing any JS code,
|
||||
see [advanced example](https://github.com/jochen-schweizer/express-prom-bundle/blob/master/advanced-example.js)
|
||||
* **promRegistry**: Optional `promClient.Registry` instance to attach metrics to. Defaults to global `promClient.register`.
|
||||
|
||||
### More details on includePath option
|
||||
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "express-prom-bundle",
|
||||
"version": "5.1.4",
|
||||
"version": "5.1.5",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
14
src/index.js
14
src/index.js
@@ -50,7 +50,8 @@ function main(opts) {
|
||||
normalizePath: main.normalizePath,
|
||||
formatStatusCode: main.normalizeStatusCode,
|
||||
metricType: 'histogram',
|
||||
promClient: {}
|
||||
promClient: {},
|
||||
promRegistry: promClient.register
|
||||
}, opts
|
||||
);
|
||||
|
||||
@@ -92,14 +93,16 @@ function main(opts) {
|
||||
labelNames: labels,
|
||||
percentiles: opts.percentiles || [0.5, 0.75, 0.95, 0.98, 0.99, 0.999],
|
||||
maxAgeSeconds: opts.maxAgeSeconds,
|
||||
ageBuckets: opts.ageBuckets
|
||||
ageBuckets: opts.ageBuckets,
|
||||
registers: [opts.promRegistry]
|
||||
});
|
||||
} else if (opts.metricType === 'histogram' || !opts.metricType) {
|
||||
return new promClient.Histogram({
|
||||
name: httpMetricName,
|
||||
help: 'duration histogram of http responses labeled with: ' + labels.join(', '),
|
||||
labelNames: labels,
|
||||
buckets: opts.buckets || [0.003, 0.03, 0.1, 0.3, 1.5, 10]
|
||||
buckets: opts.buckets || [0.003, 0.03, 0.1, 0.3, 1.5, 10],
|
||||
registers: [opts.promRegistry]
|
||||
});
|
||||
} else {
|
||||
throw new Error('metricType option must be histogram or summary');
|
||||
@@ -113,14 +116,15 @@ function main(opts) {
|
||||
if (opts.includeUp !== false) {
|
||||
metrics.up = new promClient.Gauge({
|
||||
name: 'up',
|
||||
help: '1 = up, 0 = not up'
|
||||
help: '1 = up, 0 = not up',
|
||||
registers: [opts.promRegistry]
|
||||
});
|
||||
metrics.up.set(1);
|
||||
}
|
||||
|
||||
const metricsMiddleware = function(req, res) {
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.end(promClient.register.metrics());
|
||||
res.end(opts.promRegistry.metrics());
|
||||
};
|
||||
|
||||
const metricsMatch = opts.metricsPath instanceof RegExp ? opts.metricsPath
|
||||
|
||||
3
types/index.d.ts
vendored
3
types/index.d.ts
vendored
@@ -1,7 +1,7 @@
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
import { Request, RequestHandler, Response } from 'express';
|
||||
import { DefaultMetricsCollectorConfiguration } from 'prom-client';
|
||||
import { DefaultMetricsCollectorConfiguration, Registry } from 'prom-client';
|
||||
|
||||
export {};
|
||||
|
||||
@@ -31,6 +31,7 @@ declare namespace express_prom_bundle {
|
||||
metricType?: 'summary' | 'histogram';
|
||||
metricsPath?: string;
|
||||
promClient?: { collectDefaultMetrics?: DefaultMetricsCollectorConfiguration };
|
||||
promRegistry?: Registry,
|
||||
normalizePath?: NormalizePathEntry[] | NormalizePathFn;
|
||||
formatStatusCode?: NormalizeStatusCodeFn;
|
||||
transformLabels?: TransformLabelsFn;
|
||||
|
||||
@@ -47,6 +47,7 @@ promBundle({
|
||||
timeout: 1000
|
||||
}
|
||||
},
|
||||
promRegistry: new promClient.Registry(),
|
||||
urlValueParser: {
|
||||
minHexLength: 5,
|
||||
extraMasks: [
|
||||
|
||||
Reference in New Issue
Block a user