express-prometheus-middleware
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="0.2.0"></a> | ||
# [0.2.0](https://github.com/joao-fontenele/express-prometheus-middleware/compare/v0.1.0...v0.2.0) (2018-08-14) | ||
### Features | ||
* export a middleware factory ([af1acd6](https://github.com/joao-fontenele/express-prometheus-middleware/commit/af1acd6)) | ||
<a name="0.1.0"></a> | ||
@@ -7,0 +17,0 @@ # 0.1.0 (2018-08-11) |
{ | ||
"name": "express-prometheus-middleware", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "red/use metrics for express applications", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -15,34 +15,34 @@ const express = require('express'); | ||
const app = express(); | ||
module.exports = () => { | ||
const app = express(); | ||
/** | ||
* Corresponds to the R(equest rate), E(error rate), and D(uration of requests), | ||
* of the RED metrics. | ||
*/ | ||
const redMiddleware = ResponseTime((req, res, time) => { | ||
const { path, method } = req; | ||
/** | ||
* Corresponds to the R(equest rate), E(error rate), and D(uration of requests), | ||
* of the RED metrics. | ||
*/ | ||
const redMiddleware = ResponseTime((req, res, time) => { | ||
const { path, method } = req; | ||
if (path !== '/metrics') { | ||
// will replace ids from the route with `#val` placeholder this serves to | ||
// measure the same routes, e.g., /image/id1, and /image/id2, will be | ||
// treated as the same route | ||
const route = normalizePath(path); | ||
const status = normalizeStatusCode(res.statusCode); | ||
if (path !== '/metrics') { | ||
// will replace ids from the route with `#val` placeholder this serves to | ||
// measure the same routes, e.g., /image/id1, and /image/id2, will be | ||
// treated as the same route | ||
const route = normalizePath(path); | ||
const status = normalizeStatusCode(res.statusCode); | ||
requestCount.inc({ route, method, status }); | ||
requestCount.inc({ route, method, status }); | ||
requestDuration.labels(method, route, status).observe(time); | ||
} | ||
}); | ||
requestDuration.labels(method, route, status).observe(time); | ||
} | ||
}); | ||
// when this file is required, we will start to collect automatically | ||
Prometheus.collectDefaultMetrics(); | ||
// when this file is required, we will start to collect automatically | ||
Prometheus.collectDefaultMetrics(); | ||
app.use(redMiddleware); | ||
app.use(redMiddleware); | ||
app.get('/metrics', (req, res) => { | ||
res.set('Content-Type', Prometheus.register.contentType); | ||
res.end(Prometheus.register.metrics()); | ||
}); | ||
module.exports = app; | ||
app.get('/metrics', (req, res) => { | ||
res.set('Content-Type', Prometheus.register.contentType); | ||
res.end(Prometheus.register.metrics()); | ||
}); | ||
}; |
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
91693
131