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

express-prom-bundle

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-prom-bundle - npm Package Compare versions

Comparing version 2.0.2 to 2.1.0

2

package.json
{
"name": "express-prom-bundle",
"version": "2.0.2",
"version": "2.1.0",
"description": "express middleware with popular prometheus metrics in one bundle",

@@ -5,0 +5,0 @@ "main": "src/index.js",

@@ -51,6 +51,5 @@ [![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)

* **normalizePath**: boolean or `function(req)` - path normalization for `includePath` option
* **excludeRoutes**: array of strings or regexp specifying which routes should be skipped for `http_request_duration_seconds` metric. It uses `req.path` as subject when checking
* **autoregister**: if `/metrics` endpoint should be registered. (Default: **true**)
* **whitelist**, **blacklist**: array of strings or regexp specifying which metrics to include/exclude
* **excludeRoutes**: (deprecated) array of strings or regexp specifying which routes should be skipped for `http_request_duration_seconds` metric. It uses `req.originalUrl` as subject when checking. You want normally use express or meddleware features instead of this options.
### More details on includePath option

@@ -96,4 +95,2 @@

```javascript
"use strict";
const express = require("express");

@@ -103,3 +100,2 @@ const app = express();

// calls to this route will not appear in metrics

@@ -109,8 +105,6 @@ // because it's applied before promBundle

app.use(promBundle({
includePath: true,
excludeRoutes: ["/foo"]
}));
// register metrics collection for all routes except those starting with /foo
app.use("/((?!foo))*", promBundle({includePath: true}));
// this call will NOT appear in metrics, because it matches excludeRoutes
// this call will NOT appear in metrics, because express will skip the metrics middleware
app.get("/foo", (req, res) => res.send("bar"));

@@ -141,5 +135,5 @@

## using with kraken.js
## using with kraken.js
Here is a sample **kraken.js** config file:
Here is meddleware config sample, which can be used in a standard **kraken.js** application:

@@ -149,3 +143,4 @@ ```json

"middleware": {
"prom": {
"expressPromBundle": {
"route": "/((?!status|favicon.ico|robots.txt))*",
"priority": 0,

@@ -156,5 +151,4 @@ "module": {

{
"excludeRoutes": ["/", "/robots.txt", "/status"],
"includePath": true,
"includeMethod": true
"includeMethod": true,
"buckets": [0.1, 1, 5]
}

@@ -168,5 +162,6 @@ ]

## Changelog
* **2.1.0**
* deprecate **excludeRoutes**, use **req.originalPath** instead of **req.path**
* **2.0.0**

@@ -173,0 +168,0 @@ * the reason for the version lift were:

'use strict';
const onFinished = require('on-finished');
const url = require('url');
const promClient = require('prom-client');

@@ -42,3 +41,3 @@ const normalizePath = require('./normalizePath');

function main(opts) {
opts = Object.assign({autoregister: true}, opts || {});
opts = Object.assign({autoregister: true}, opts);
if (arguments[2] && arguments[1] && arguments[1].send) {

@@ -100,3 +99,3 @@ arguments[1].status(500)

const metricsMiddleware = function(req,res) {
const metricsMiddleware = function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});

@@ -107,8 +106,7 @@ res.end(promClient.register.metrics());

const middleware = function (req, res, next) {
const path = req.path || url.parse(req.url).pathname;
const path = req.originalUrl;
let labels;
if (opts.autoregister && path === '/metrics') {
return metricsMiddleware(req,res);
if (opts.autoregister && path.match(/^\/metrics\/?$/)) {
return metricsMiddleware(req, res);
}

@@ -115,0 +113,0 @@

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