diff --git a/README.md b/README.md index c3a7b50..42741b7 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,9 @@ Other options: * **buckets**: buckets used for `http_request_duration_seconds` histogram * **autoregister**: if `/metrics` endpoint should be registered. (Default: **true**) +* **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) Deprecated: @@ -171,19 +174,32 @@ Here is meddleware config sample, which can be used in a standard **kraken.js** ## Changelog + * **3.3.0** + * added option **promClient** to be able to call collectDefaultMetrics + * upgrade **prom-client** to ~10.2.2 (switch to semver "approximately") + + * **3.2.0** * added options **customLabels**, **transformLabels** * upgrade **prom-client** to 10.1.0 + + * **3.1.0** * upgrade **prom-client** to 10.0.0 + + * **3.0.0** * upgrade dependencies, most notably **prom-client** to 9.0.0 * switch to koa v2 in koa unittest * only node v6 or higher is supported (stop supporting node v4 and v5) * switch to npm5 and use package-lock.json * options added: includeStatusCode, formatStatusCode + + * **2.1.0** * deprecate **excludeRoutes**, use **req.originalUrl** instead of **req.path** + + * **2.0.0** * the reason for the version lift were: * compliance to official naming recommendation: https://prometheus.io/docs/practices/naming/ diff --git a/advanced-example.js b/advanced-example.js index b180a14..c46a75b 100644 --- a/advanced-example.js +++ b/advanced-example.js @@ -10,13 +10,18 @@ const bundle = promBundle({ includeMethod: true, includePath: true, customLabels: {year: null}, - transformLabels: labels => Object.assign(labels, {year: new Date().getFullYear()}) + transformLabels: labels => Object.assign(labels, {year: new Date().getFullYear()}), + promClient: { + collectDefaultMetrics: { + timeout: 1000 + } + } }); app.use(bundle); // native prom-client metric (no prefix) -const c1 = new bundle.promClient.Counter('c1', 'c1 help'); +const c1 = new bundle.promClient.Counter({name: 'c1', help: 'c1 help'}); c1.inc(10); app.get('/foo/:id', (req, res) => { diff --git a/package-lock.json b/package-lock.json index 86c263d..fec5b48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "express-prom-bundle", - "version": "3.2.0", + "version": "3.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -1896,9 +1896,9 @@ "dev": true }, "prom-client": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-10.1.0.tgz", - "integrity": "sha512-ny9EdxpG6UcNnuc3W3LedE9qC3RFLSD+aBCv1i9OtcLS/nyHFck5uncoWHpD+rxmdttUPVd8qYRT1rb15Lpmjg==", + "version": "10.2.2", + "resolved": "https://registry.npmjs.org/prom-client/-/prom-client-10.2.2.tgz", + "integrity": "sha512-d3qCBK41qZx00/WVzWOX4tau9FinCztqaECZiGuMI5vGYD//5VSdKMOZPRQKjVh5RkI4Ex98DI0YPsoFnEo1QQ==", "requires": { "tdigest": "0.1.1" } diff --git a/package.json b/package.json index 52f4e25..f8c827e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-prom-bundle", - "version": "3.2.1", + "version": "3.3.0", "description": "express middleware with popular prometheus metrics in one bundle", "main": "src/index.js", "keywords": [ @@ -17,7 +17,7 @@ "license": "MIT", "dependencies": { "on-finished": "^2.3.0", - "prom-client": "^10.1.0", + "prom-client": "~10.2.2", "url-value-parser": "^1.0.0" }, "devDependencies": { diff --git a/spec/index.spec.js b/spec/index.spec.js index 6079b83..c0a9d80 100644 --- a/spec/index.spec.js +++ b/spec/index.spec.js @@ -343,4 +343,16 @@ describe('index', () => { }); }); }); + + it('calls promClient.collectDefaultMetrics', () => { + const spy = spyOn(promClient, 'collectDefaultMetrics'); + bundle({ + promClient: { + collectDefaultMetrics: { + timeout: 3000 + } + } + }); + expect(spy).toHaveBeenCalledWith({timeout: 3000}); + }); }); diff --git a/src/index.js b/src/index.js index a2fd3db..b582510 100644 --- a/src/index.js +++ b/src/index.js @@ -44,7 +44,8 @@ function main(opts) { autoregister: true, includeStatusCode: true, normalizePath: main.normalizePath, - formatStatusCode: main.normalizeStatusCode + formatStatusCode: main.normalizeStatusCode, + promClient: {} }, opts ); @@ -66,6 +67,10 @@ function main(opts) { ); } + if (opts.promClient.collectDefaultMetrics) { + promClient.collectDefaultMetrics(opts.promClient.collectDefaultMetrics); + } + const httpMetricName = opts.httpDurationMetricName || 'http_request_duration_seconds'; const metricTemplates = {