express-prom-bundle
Advanced tools
Comparing version 2.0.1 to 2.0.2
{ | ||
"name": "express-prom-bundle", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "express middleware with popular prometheus metrics in one bundle", | ||
@@ -10,3 +10,4 @@ "main": "src/index.js", | ||
"express", | ||
"bundle" | ||
"path", | ||
"method" | ||
], | ||
@@ -13,0 +14,0 @@ "scripts": { |
@@ -59,9 +59,30 @@ [![build status](https://travis-ci.org/jochen-schweizer/express-prom-bundle.png)](https://travis-ci.org/jochen-schweizer/express-prom-bundle) [![Coverage Status](https://coveralls.io/repos/github/jochen-schweizer/express-prom-bundle/badge.svg?branch=master)](https://coveralls.io/github/jochen-schweizer/express-prom-bundle?branch=master) [![license](https://img.shields.io/github/license/mashape/apistatus.svg?maxAge=2592000)](https://www.tldrlegal.com/l/mit) [![NPM version](https://badge.fury.io/js/express-prom-bundle.png)](http://badge.fury.io/js/express-prom-bundle) | ||
Just taking `req.path` as a label value won't work as IDs are often part of the URL, like `/user/12352/profile`. So what we actually need is a path template. The module tries to figure out what parts of the path are values or IDs, and what is an actual path. The example mentioned before would be normalized to `/user/#val/profile` and that will become the value for the label. | ||
Just taking `req.path` as a label value won't work as IDs are often part of the URL, | ||
like `/user/12352/profile`. So what we actually need is a path template. | ||
The module tries to figure out what parts of the path are values or IDs, | ||
and what is an actual path. The example mentioned before would be | ||
normalized to `/user/#val/profile` and that will become the value for the label. | ||
You can override this magical behavior and define your own function by providing an optional callback using **normalizePath** option. | ||
You can override this magical behavior and define your own function by | ||
providing an optional callback using **normalizePath** option. | ||
You can also replace the default **normalizePath** function globally. | ||
This is handy if the rest of the middleware is done elsewhere | ||
e.g. via `kraken.js meddleware`. | ||
```javascript | ||
app.use(promBundle(/* options? */)); | ||
// let's reuse the existing one and just add some | ||
// functionality on top | ||
const originalNormalize = promBunle.normalizePath; | ||
promBunle.normalizePath = (req, opts) => { | ||
const path = originalNormalize(req, opts); | ||
// count all docs (no matter which file) as a single path | ||
return path.match(/^\/docs/) ? '/docs/*' : path; | ||
}; | ||
``` | ||
For more details: | ||
* [url-value-parser](https://www.npmjs.com/package/url-value-parser) - magic behind automatic path normalization | ||
* [normalizePath.js](https://github.com/jochen-schweizer/express-prom-bundle/blob/master/src/normalizePath.js) - source code for path processing, for you | ||
* [normalizePath.js](https://github.com/jochen-schweizer/express-prom-bundle/blob/master/src/normalizePath.js) - source code for path processing | ||
@@ -117,2 +138,27 @@ | ||
## using with kraken.js | ||
Here is a sample **kraken.js** config file: | ||
```json | ||
{ | ||
"middleware": { | ||
"prom": { | ||
"priority": 0, | ||
"module": { | ||
"name": "express-prom-bundle", | ||
"arguments": [ | ||
{ | ||
"excludeRoutes": ["/", "/robots.txt", "/status"], | ||
"includePath": true, | ||
"includeMethod": true | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
## Changelog | ||
@@ -119,0 +165,0 @@ |
@@ -126,3 +126,3 @@ 'use strict'; | ||
if (opts.includePath) { | ||
labels.path = normalizePath(req, opts); | ||
labels.path = main.normalizePath(req, opts); | ||
} | ||
@@ -144,2 +144,3 @@ timer(); | ||
main.promClient = promClient; | ||
main.normalizePath = normalizePath; | ||
module.exports = main; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13334
146
183