express-prometheus-middleware
Advanced tools
Comparing version 0.8.4 to 0.8.5
@@ -5,2 +5,9 @@ # Changelog | ||
### [0.8.5](https://github.com/joao-fontenele/express-prometheus-middleware/compare/v0.8.4...v0.8.5) (2019-11-23) | ||
### Features | ||
* **prefix:** Allow adding metrics prefix name ([ead5c1a](https://github.com/joao-fontenele/express-prometheus-middleware/commit/ead5c1a4ecf1ba2888784050589c4ed359b8f182)) | ||
### [0.8.4](https://github.com/joao-fontenele/express-prometheus-middleware/compare/v0.8.3...v0.8.4) (2019-11-15) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "express-prometheus-middleware", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "RED/USE metrics for express applications", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -33,2 +33,3 @@ # Express Prometheus Middleware | ||
| authenticate | Optional authentication callback, the function should receive as argument, the `req` object and return truthy for sucessfull authentication, or falsy, otherwise. This option supports Promise results. | `null` | | ||
| prefix | Optional prefix for the metrics name | no prefix added | | | ||
@@ -35,0 +36,0 @@ ### Example |
@@ -6,3 +6,3 @@ const express = require('express'); | ||
const { | ||
requestCount, | ||
requestCountGenerator, | ||
requestDurationGenerator, | ||
@@ -36,3 +36,4 @@ } = require('./metrics'); | ||
const requestDuration = requestDurationGenerator(options.requestDurationBuckets); | ||
const requestDuration = requestDurationGenerator(options.requestDurationBuckets, options.prefix); | ||
const requestCount = requestCountGenerator(options.prefix); | ||
@@ -64,3 +65,5 @@ /** | ||
// used to calculate saturation of the service | ||
Prometheus.collectDefaultMetrics(); | ||
Prometheus.collectDefaultMetrics({ | ||
prefix: options.prefix, | ||
}); | ||
} | ||
@@ -67,0 +70,0 @@ |
const Prometheus = require('prom-client'); | ||
const requestCount = new Prometheus.Counter({ | ||
name: 'http_requests_total', | ||
help: 'Counter for total requests received', | ||
labelNames: ['route', 'method', 'status'], | ||
}); | ||
/** | ||
* @param prefix - metrics name prefix | ||
* request counter | ||
*/ | ||
function requestCountGenerator(prefix = '') { | ||
return new Prometheus.Counter({ | ||
name: `${prefix}http_requests_total`, | ||
help: 'Counter for total requests received', | ||
labelNames: ['route', 'method', 'status'], | ||
}); | ||
} | ||
/** | ||
* @param {!Array} buckets - array of numbers, representing the buckets for | ||
* @param prefix - metrics name prefix | ||
* request duration | ||
*/ | ||
function requestDurationGenerator(buckets) { | ||
function requestDurationGenerator(buckets, prefix = '') { | ||
return new Prometheus.Histogram({ | ||
name: 'http_request_duration_seconds', | ||
name: `${prefix}http_request_duration_seconds`, | ||
help: 'Duration of HTTP requests in seconds', | ||
@@ -23,4 +30,4 @@ labelNames: ['route', 'method', 'status'], | ||
module.exports = { | ||
requestCount, | ||
requestCountGenerator, | ||
requestDurationGenerator, | ||
}; |
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
18452
198
141