Socket
Socket
Sign inDemoInstall

fastify-metrics

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-metrics - npm Package Compare versions

Comparing version 6.0.0-rc.3 to 6.0.0-rc.4

21

CHANGELOG.md

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

## [6.0.0-rc.4](https://github.com/SkeLLLa/fastify-metrics/compare/v6.0.0-rc.3...v6.0.0-rc.4) (2020-06-06)
### Features
* add flags for enabling/disabling route metrics ([3da8352](https://github.com/SkeLLLa/fastify-metrics/commit/3da83524010f424b08dd4e39ae5f32505b47a7ec))
* replace options extend ([e92f07e](https://github.com/SkeLLLa/fastify-metrics/commit/e92f07e4f11e79a709a8b56fc67fc78832cdfc95))
### Bug fixes
* **jest:** reports fix ([9aa6453](https://github.com/SkeLLLa/fastify-metrics/commit/9aa6453d8e3de787ad41c57eb5d8bf69b98ce666))
### Misc
* **deps:** update ([6f6803a](https://github.com/SkeLLLa/fastify-metrics/commit/6f6803a0ac22f559017287eee863b6d0bbb9d8fb))
* badges fix ([3014d89](https://github.com/SkeLLLa/fastify-metrics/commit/3014d891462257e67c3106aa03ee90474362080e))
* date update ([e2b40de](https://github.com/SkeLLLa/fastify-metrics/commit/e2b40de61beaecf495d2936efde824f0c3433e6d))
* issues url ([97a5aca](https://github.com/SkeLLLa/fastify-metrics/commit/97a5aca63008788bd8aef2a6a66deb5cc868f3cb))
## [6.0.0-rc.3](https://github.com/SkeLLLa/fastify-metrics/compare/v6.0.0-rc.2...v6.0.0-rc.3) (2020-05-24)

@@ -7,0 +28,0 @@

37

dist/index.js

@@ -7,3 +7,2 @@ "use strict";

const prom_client_1 = __importDefault(require("prom-client"));
const deepmerge_1 = __importDefault(require("deepmerge"));
/**

@@ -13,5 +12,23 @@ * Fastify metrics plugin

*/
const fastifyMetricsPlugin = async function fastifyMetrics(fastify, { enableDefaultMetrics = true, groupStatusCodes = false, pluginName = 'metrics', blacklist, register, prefix, endpoint, metrics = {}, } = {}) {
const plugin = { client: prom_client_1.default };
const fastifyMetricsPlugin = async function fastifyMetrics(fastify, { enableDefaultMetrics = true, enableRouteMetrics = true, groupStatusCodes = false, pluginName = 'metrics', blacklist, register, prefix, endpoint, metrics = {}, } = {}) {
const plugin = {
client: prom_client_1.default,
clearRegister: function () {
// dummy fn;
},
};
const defaultOpts = {};
if (register) {
plugin.clearRegister = () => {
register.clear();
};
defaultOpts.register = register;
}
if (prefix) {
defaultOpts.prefix = prefix;
}
if (enableDefaultMetrics) {
prom_client_1.default.collectDefaultMetrics(defaultOpts);
}
if (enableRouteMetrics) {
const collectMetricsForUrl = (url) => {

@@ -34,3 +51,2 @@ const queryIndex = url.indexOf('?');

};
const defaultOpts = {};
const opts = {

@@ -42,2 +58,3 @@ histogram: {

buckets: [0.05, 0.1, 0.5, 1, 3, 5, 10],
...metrics.histogram,
},

@@ -49,9 +66,6 @@ summary: {

percentiles: [0.5, 0.9, 0.95, 0.99],
...metrics.summary,
},
};
if (register) {
plugin.clearRegister = () => {
register.clear();
};
defaultOpts.register = register;
opts.histogram.registers = [register];

@@ -61,10 +75,7 @@ opts.summary.registers = [register];

if (prefix) {
defaultOpts.prefix = prefix;
opts.histogram.name = `${prefix}${opts.histogram.name}`;
opts.summary.name = `${prefix}${opts.summary.name}`;
}
const extendedOpts = deepmerge_1.default(opts, metrics);
prom_client_1.default.collectDefaultMetrics(defaultOpts);
const routeHist = new prom_client_1.default.Histogram(extendedOpts.histogram);
const routeSum = new prom_client_1.default.Summary(extendedOpts.summary);
const routeHist = new prom_client_1.default.Histogram(opts.histogram);
const routeSum = new prom_client_1.default.Summary(opts.summary);
if (endpoint) {

@@ -71,0 +82,0 @@ fastify.route({

@@ -24,3 +24,3 @@ import promClient, { HistogramConfiguration, SummaryConfiguration } from 'prom-client';

*/
clearRegister?(): void;
clearRegister(): void;
/**

@@ -33,3 +33,3 @@ * Additional objects to store your metrics, registries, etc.

/**
* Enable default nodejs metrics
* Enable default prom-client metrics
* @default true

@@ -39,2 +39,7 @@ */

/**
* Enable fastify route metrics
* @default true
*/
enableRouteMetrics?: boolean;
/**
* Groups status code labels by first digit 200 -> 2XX

@@ -41,0 +46,0 @@ * @default false

{
"name": "fastify-metrics",
"version": "6.0.0-rc.3",
"version": "6.0.0-rc.4",
"description": "Prometheus metrics exporter for Fastify",
"keywords": [
"fastify-plugin",
"metrics",
"prometheus",
"fastify",
"prometheus",
"metrics"
"plugin"
],
"homepage": "https://gitlab.com/m03geek/fastify-metrics#README",
"bugs": {
"url": "https://gitlab.com/m03geek/fastify-metrics/issues"
"url": "https://github.com/SkeLLLa/fastify-metrics/issues"
},

@@ -21,4 +23,4 @@ "repository": {

"main": "dist/index.js",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"module": "dist/index.js",
"directories": {

@@ -28,4 +30,4 @@ "doc": "docs"

"scripts": {
"build": "tsc",
"get-changelog": "conventional-changelog -r 2 -p angular",
"build": "tsc",
"lint": "eslint .",

@@ -39,7 +41,3 @@ "prerelease": "npm run typedoc",

},
"config": {
"releaseBranch": "master"
},
"dependencies": {
"deepmerge": "^4.2.2",
"fastify-plugin": "^2.0.0",

@@ -52,12 +50,12 @@ "prom-client": "^12.0.0"

"@types/jest": "^25.2.3",
"@types/node": "^14.0.0",
"@typescript-eslint/eslint-plugin": "^3.0.0",
"@typescript-eslint/parser": "^3.0.0",
"@types/node": "^14.0.11",
"@typescript-eslint/eslint-plugin": "^3.1.0",
"@typescript-eslint/parser": "^3.1.0",
"codecov": "^3.7.0",
"conventional-changelog-cli": "^2.0.34",
"eslint": "^7.0.0",
"eslint": "^7.2.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^6.11.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jest": "^23.10.0",
"eslint-plugin-jest": "^23.13.2",
"eslint-plugin-prettier": "^3.1.3",

@@ -69,12 +67,12 @@ "eslint-plugin-sort-requires": "^2.1.0",

"prettier": "^2.0.5",
"prettier-plugin-packagejson": "^2.2.3",
"prettier-plugin-packagejson": "^2.2.5",
"pretty-quick": "^2.0.1",
"replace": "^1.2.0",
"standard-version": "^8.0.0",
"ts-jest": "^26.0.0",
"ts-node": "^8.10.1",
"ts-jest": "^26.1.0",
"ts-node": "^8.10.2",
"typedoc": "^0.17.0",
"typedoc-plugin-markdown": "^2.2.10",
"typescript": "^3.8.3"
"typedoc-plugin-markdown": "^2.3.1",
"typescript": "^3.9.5"
}
}

@@ -14,3 +14,3 @@ # fastify-metrics

[![LGTM Alerts](https://img.shields.io/lgtm/alerts/github/SkeLLLa/fastify-metrics.svg)](https://lgtm.com/projects/g/SkeLLLa/fastify-metrics/)
[![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/SkeLLLa/yammy.svg)](https://lgtm.com/projects/g/SkeLLLa/fastify-metrics/)
[![LGTM Grade](https://img.shields.io/lgtm/grade/javascript/github/SkeLLLa/fastify-metrics.svg)](https://lgtm.com/projects/g/SkeLLLa/fastify-metrics/)

@@ -31,2 +31,4 @@ [Prometheus](https://prometheus.io/) metrics exporter for Fastify.

- [Fastify support](#fastify-support)
- [Notable changes](#notable-changes)
- [v6.x.x](#v6xx)
- [Installation](#installation)

@@ -50,2 +52,11 @@ - [Features and requirements](#features-and-requirements)

## Notable changes
### v6.x.x
- Fastify v3 support.
- Drop node.js 8 support.
- `enableDefaultMetrics` - now enables only default `prom-client` metrics. Set to `true` by default.
- `enableRouteMetrics` - additianal flag that enables route metrics. Set to `true` by default.
## Installation

@@ -67,4 +78,4 @@

- Requires fastify `>=1.9.0`.
- Node.js `>=8.9.0`.
- Requires fastify `>=3.0.0`.
- Node.js `>=10.0.0`.

@@ -93,13 +104,14 @@ <sub>[Back to top](#toc)</sub>

| parameter | type | description | default |
| ---------------------- | ------------------------ | -------------------------------------------------------------------------------------------------------- | ----------- |
| `enableDefaultMetrics` | Boolean | Enables collection of default metrics. | `true` |
| `pluginName` | String | Change name which you'll use to access prometheus client instance in fastify. | `metrics` |
| `interval` | Number | Default metrics collection interval in ms. | `5000` |
| `register` | Object | Custom prom-client metrics registry (see [docs](https://github.com/siimon/prom-client#default-metrics)). | `undefined` |
| `prefix` | String | Custom default metrics prefix. | `""` |
| `endpoint` | String | If set, fastify route will be added to expose metrics. If not set you may manually add it afterwards. | `undefined` |
| `metrics` | Object | Allows override default metrics config. See section below. | `{}` |
| `blacklist` | String, RegExp, String[] | Skip metrics collection for blacklisted routes | `undefined` |
| `groupStatusCodes` | Boolean | Groups status codes (e.g. 2XX) if `true` | `false` |
| parameter | type | description | default |
| ---------------------- | ------------------------ | ----------------------------------------------------------------------------------------------------- | ----------- |
| `enableDefaultMetrics` | Boolean | Enables collection of default prom-client metrics. | `true` |
| `enableRouteMetrics` | Boolean | Enables collection of fastify route metrics. | `true` |
| `pluginName` | String | Change name which you'll use to access prometheus client instance in fastify. | `metrics` |
| `interval` | Number | Default metrics collection interval in ms. | `5000` |
| `register` | Object | Custom prom-client metrics registry. | `undefined` |
| `prefix` | String | Custom default metrics prefix. | `""` |
| `endpoint` | String | If set, fastify route will be added to expose metrics. If not set you may manually add it afterwards. | `undefined` |
| `metrics` | Object | Allows override default metrics config. See section below. | `{}` |
| `blacklist` | String, RegExp, String[] | Skip metrics collection for blacklisted routes | `undefined` |
| `groupStatusCodes` | Boolean | Groups status codes (e.g. 2XX) if `true` | `false` |

@@ -106,0 +118,0 @@ #### Metrics details

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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