express-prom-bundle
Advanced tools
Comparing version 6.6.0 to 7.0.0
{ | ||
"name": "express-prom-bundle", | ||
"version": "6.6.0", | ||
"version": "7.0.0", | ||
"description": "express middleware with popular prometheus metrics in one bundle", | ||
@@ -17,3 +17,3 @@ "main": "src/index.js", | ||
], | ||
"types": "types", | ||
"types": "types/index.d.ts", | ||
"scripts": { | ||
@@ -23,4 +23,3 @@ "test": "NODE_ENV=test node_modules/jasme/run.js", | ||
"coverage": "make coverage", | ||
"dtslint": "dtslint types", | ||
"dtslint-next": "dtslint --onlyTestTsNext types" | ||
"test-types": "tsd" | ||
}, | ||
@@ -30,2 +29,4 @@ "author": "Konstantin Pogorelov <or@pluseq.com>", | ||
"dependencies": { | ||
"@types/express": "^4.17.21", | ||
"express": "^4.18.2", | ||
"on-finished": "^2.3.0", | ||
@@ -35,7 +36,4 @@ "url-value-parser": "^2.0.0" | ||
"devDependencies": { | ||
"@types/express": "^4.16.1", | ||
"coveralls": "^3.0.2", | ||
"dtslint": "^0.7.1", | ||
"dts": "^0.1.1", | ||
"eslint": "^5.11.0", | ||
"express": "^4.16.4", | ||
"istanbul": "^0.4.5", | ||
@@ -45,9 +43,10 @@ "jasme": "^6.0.0", | ||
"koa-connect": "^2.0.1", | ||
"prom-client": "^13.0.0", | ||
"prom-client": "^15.0.0", | ||
"supertest": "^3.3.0", | ||
"supertest-koa-agent": "^0.3.0", | ||
"tsd": "^0.30.3", | ||
"typescript": "^3.4.5" | ||
}, | ||
"peerDependencies": { | ||
"prom-client": ">=12.0.0" | ||
"prom-client": ">=15.0.0" | ||
}, | ||
@@ -59,4 +58,4 @@ "repository": { | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=18" | ||
} | ||
} |
@@ -7,4 +7,6 @@ [![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) | ||
Since version 5 it uses **prom-client** as a peer dependency. See: https://github.com/siimon/prom-client | ||
This library uses **prom-client v15+** as a peer dependency. See: https://github.com/siimon/prom-client | ||
If you need a support for older versions of prom-client (v12-v14), downgrade to express-prom-bundle v6.6.0 | ||
Included metrics: | ||
@@ -71,2 +73,3 @@ | ||
* **maxAgeSeconds**: the maxAgeSeconds will tell how old a bucket can be before it is reset | ||
* **pruneAgedBuckets**: When enabled, timed out buckets will be removed entirely. By default, buckets are reset to 0. | ||
@@ -164,2 +167,13 @@ ### Transformation callbacks ### | ||
#### Example 3 (return express route definition): | ||
```javascript | ||
app.use(promBundle(/* options? */)); | ||
promBundle.normalizePath = (req, opts) => { | ||
// Return the path of the express route (i.e. /v1/user/:id or /v1/timer/automated/:userid/:timerid") | ||
return req.route?.path ?? "NULL"; | ||
}; | ||
``` | ||
## express example | ||
@@ -166,0 +180,0 @@ |
@@ -115,3 +115,4 @@ const onFinished = require('on-finished'); | ||
ageBuckets: opts.ageBuckets, | ||
registers: [opts.promRegistry] | ||
registers: [opts.promRegistry], | ||
pruneAgedBuckets: opts.pruneAgedBuckets | ||
}); | ||
@@ -136,4 +137,8 @@ } else if (opts.metricType === 'histogram' || !opts.metricType) { | ||
if (opts.includeUp !== false) { | ||
let prefix = ''; | ||
if (opts.promClient && opts.promClient.collectDefaultMetrics) { | ||
prefix = opts.promClient.collectDefaultMetrics.prefix || ''; | ||
} | ||
metrics.up = new promClient.Gauge({ | ||
name: 'up', | ||
name: `${prefix}up`, | ||
help: '1 = up, 0 = not up', | ||
@@ -140,0 +145,0 @@ registers: [opts.promRegistry] |
'use strict'; | ||
const CLIENT_CLOSED_REQUEST_CODE = 499; | ||
module.exports = function(res) { | ||
return res.status_code || res.statusCode; | ||
if (res.headersSent) { | ||
return res.status_code || res.statusCode; | ||
} else { | ||
return CLIENT_CLOSED_REQUEST_CODE; | ||
} | ||
}; |
// TypeScript Version: 2.8 | ||
import { Request, RequestHandler, Response, Express } from 'express'; | ||
import { DefaultMetricsCollectorConfiguration, Registry } from 'prom-client'; | ||
import { DefaultMetricsCollectorConfiguration, Registry, RegistryContentType } from 'prom-client'; | ||
@@ -20,3 +20,3 @@ export {}; | ||
interface Opts { | ||
interface BaseOptions { | ||
autoregister?: boolean; | ||
@@ -40,15 +40,5 @@ | ||
metricType?: 'summary' | 'histogram'; | ||
// https://github.com/siimon/prom-client#histogram | ||
buckets?: number[]; | ||
// https://github.com/siimon/prom-client#summary | ||
percentiles?: number[]; | ||
maxAgeSeconds?: number; | ||
ageBuckets?: number; | ||
metricsPath?: string; | ||
httpDurationMetricName?: string; | ||
promClient?: { collectDefaultMetrics?: DefaultMetricsCollectorConfiguration }; | ||
promClient?: { collectDefaultMetrics?: DefaultMetricsCollectorConfiguration<RegistryContentType> }; | ||
promRegistry?: Registry; | ||
@@ -70,2 +60,19 @@ normalizePath?: NormalizePathEntry[] | NormalizePathFn; | ||
/** @see https://github.com/siimon/prom-client#summary */ | ||
type SummaryOptions = BaseOptions & { | ||
metricType?: 'summary'; | ||
percentiles?: number[]; | ||
maxAgeSeconds?: number; | ||
ageBuckets?: number; | ||
pruneAgedBuckets?: boolean; | ||
} | ||
/** @see https://github.com/siimon/prom-client#histogram */ | ||
type HistogramOptions = BaseOptions & { | ||
metricType?: 'histogram'; | ||
buckets?: number[]; | ||
} | ||
type Opts = SummaryOptions | HistogramOptions; | ||
interface Middleware extends RequestHandler { | ||
@@ -72,0 +79,0 @@ metricsMiddleware: RequestHandler; |
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
25370
11
318
298
5
+ Added@types/express@^4.17.21
+ Addedexpress@^4.18.2
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/express@4.17.21(transitive)
+ Added@types/express-serve-static-core@4.19.6(transitive)
+ Added@types/http-errors@2.0.4(transitive)
+ Added@types/mime@1.3.5(transitive)
+ Added@types/node@22.9.0(transitive)
+ Added@types/qs@6.9.17(transitive)
+ Added@types/range-parser@1.2.7(transitive)
+ Added@types/send@0.17.4(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Addedaccepts@1.3.8(transitive)
+ Addedarray-flatten@1.1.1(transitive)
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.7.1(transitive)
+ Addedcookie-signature@1.0.6(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedexpress@4.21.1(transitive)
+ Addedfinalhandler@1.3.1(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmerge-descriptors@1.0.3(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpath-to-regexp@0.1.10(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedqs@6.13.0(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedundici-types@6.19.8(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addedutils-merge@1.0.1(transitive)
+ Addedvary@1.1.2(transitive)