Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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 0.8.4 to 0.8.5

7

CHANGELOG.md

@@ -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 @@

2

package.json
{
"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,
};
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