Socket
Socket
Sign inDemoInstall

express-prometheus-middleware

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-prometheus-middleware - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

12

CHANGELOG.md

@@ -5,2 +5,14 @@ # Changelog

## [1.2.0](https://github.com/joao-fontenele/express-prometheus-middleware/compare/v1.1.0...v1.2.0) (2021-04-24)
### Features
* add metrics for request length and response length ([30ec2ed](https://github.com/joao-fontenele/express-prometheus-middleware/commit/30ec2eddf660858a22a6677571d8f3afd022d241))
### Bug Fixes
* commitlint misreporting release commit ([cbd4101](https://github.com/joao-fontenele/express-prometheus-middleware/commit/cbd410192dd7bf8003a56471ecae145274377267))
## [1.1.0](https://github.com/joao-fontenele/express-prometheus-middleware/compare/v1.0.0...v1.1.0) (2021-02-19)

@@ -7,0 +19,0 @@

4

package.json
{
"name": "express-prometheus-middleware",
"version": "1.1.0",
"version": "1.2.0",
"description": "RED/USE metrics for express applications",

@@ -33,3 +33,3 @@ "keywords": [

"prom-client": ">= 10.x <= 13.x",
"standard-version": "^8.0.1"
"standard-version": "^9.2.0"
},

@@ -36,0 +36,0 @@ "dependencies": {

@@ -32,2 +32,4 @@ # Express Prometheus Middleware

| requestDurationBuckets | Buckets for the request duration metrics (in seconds) histogram | Uses `prom-client` utility: `Prometheus.exponentialBuckets(0.05, 1.75, 8)` |
| requestLengthBuckets | Buckets for the request length metrics (in bytes) histogram | no buckets (The request length metrics are not collected): `[]` |
| responseLengthBuckets | Buckets for the response length metrics (in bytes) histogram | no buckets (The response length metrics are not collected) `[]` |
| extraMasks | Optional, list of regexes to be used as argument to [url-value-parser](https://www.npmjs.com/package/url-value-parser), this will cause extra route params, to be replaced with a `#val` placeholder. | no extra masks: `[]` |

@@ -51,2 +53,4 @@ | 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` |

requestDurationBuckets: [0.1, 0.5, 1, 1.5],
requestLengthBuckets: [512, 1024, 5120, 10240, 51200, 102400],
responseLengthBuckets: [512, 1024, 5120, 10240, 51200, 102400],
/**

@@ -127,2 +131,14 @@ * Uncomenting the `authenticate` callback will make the `metricsPath` route

#### 95% of request length
```js
histogram_quantile(0.95, sum(rate(http_request_length_bytes_bucket{app="myapp"}[5m])) by (le))
```
#### 95% of response length
```js
histogram_quantile(0.95, sum(rate(http_response_length_bytes_bucket{app="myapp"}[5m])) by (le))
```
#### Average response time in seconds

@@ -129,0 +145,0 @@

@@ -8,2 +8,4 @@ const express = require('express');

requestDurationGenerator,
requestLengthGenerator,
responseLengthGenerator,
} = require('./metrics');

@@ -23,4 +25,6 @@

// buckets for response time from 0.05s to 2.5s
// these are aribtrary values since i dont know any better ¯\_(ツ)_/¯
// these are arbitrary values since i dont know any better ¯\_(ツ)_/¯
requestDurationBuckets: Prometheus.exponentialBuckets(0.05, 1.75, 8),
requestLengthBuckets: [],
responseLengthBuckets: [],
extraMasks: [],

@@ -51,2 +55,12 @@ customLabels: [],

);
const requestLength = requestLengthGenerator(
options.customLabels,
options.requestLengthBuckets,
options.prefix,
);
const responseLength = responseLengthGenerator(
options.customLabels,
options.responseLengthBuckets,
options.prefix,
);

@@ -77,2 +91,18 @@ /**

requestDuration.observe(labels, time / 1000);
// observe request length
if (options.requestLengthBuckets.length) {
const reqLength = req.get('Content-Length');
if (reqLength) {
requestLength.observe(labels, Number(reqLength));
}
}
// observe response length
if (options.responseLengthBuckets.length) {
const resLength = res.get('Content-Length');
if (resLength) {
responseLength.observe(labels, Number(resLength));
}
}
}

@@ -79,0 +109,0 @@ });

@@ -29,5 +29,35 @@ const Prometheus = require('prom-client');

/**
* @param {!Array} buckets - array of numbers, representing the buckets for
* @param prefix - metrics name prefix
* request length
*/
function requestLengthGenerator(labelNames, buckets, prefix = '') {
return new Prometheus.Histogram({
name: `${prefix}http_request_length_bytes`,
help: 'Content-Length of HTTP request',
labelNames,
buckets,
});
}
/**
* @param {!Array} buckets - array of numbers, representing the buckets for
* @param prefix - metrics name prefix
* response length
*/
function responseLengthGenerator(labelNames, buckets, prefix = '') {
return new Prometheus.Histogram({
name: `${prefix}http_response_length_bytes`,
help: 'Content-Length of HTTP response',
labelNames,
buckets,
});
}
module.exports = {
requestCountGenerator,
requestDurationGenerator,
requestLengthGenerator,
responseLengthGenerator,
};
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc