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 10.3.3 to 10.6.0

5

dist/fastify-metrics.d.ts

@@ -58,2 +58,7 @@ import { FastifyInstance } from 'fastify';

private registerRouteMetrics;
/**
* Create timers for histogram and summary based on enabled configuration
* option
*/
private createTimers;
/** Collect per-route metrics */

@@ -60,0 +65,0 @@ private collectRouteMetrics;

46

dist/fastify-metrics.js

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

},
promClient: null,
};

@@ -83,3 +84,6 @@ /**

// routeOptions.prefix;
if (this.options.routeMetrics.routeBlacklist?.includes(routeOptions.url)) {
const isRouteBlacklisted = this.options.routeMetrics.routeBlacklist?.some((pattern) => typeof pattern === 'string'
? pattern === routeOptions.url
: pattern.test(routeOptions.url));
if (isRouteBlacklisted) {
return;

@@ -206,2 +210,26 @@ }

}
/**
* Create timers for histogram and summary based on enabled configuration
* option
*/
createTimers(request) {
if (this.options.routeMetrics.enabled instanceof Object) {
this.metricStorage.set(request, {
hist: !(this.options.routeMetrics.enabled.histogram === false)
? this.routeMetrics.routeHist.startTimer()
: undefined,
sum: !(this.options.routeMetrics.enabled.summary === false)
? this.routeMetrics.routeSum.startTimer()
: undefined,
});
return;
}
if (!(this.options.routeMetrics.enabled === false)) {
this.metricStorage.set(request, {
hist: this.routeMetrics.routeHist.startTimer(),
sum: this.routeMetrics.routeSum.startTimer(),
});
}
return;
}
/** Collect per-route metrics */

@@ -219,6 +247,3 @@ collectRouteMetrics() {

request.method)) {
this.metricStorage.set(request, {
hist: this.routeMetrics.routeHist.startTimer(),
sum: this.routeMetrics.routeSum.startTimer(),
});
this.createTimers(request);
}

@@ -231,6 +256,3 @@ return done();

}))) {
this.metricStorage.set(request, {
hist: this.routeMetrics.routeHist.startTimer(),
sum: this.routeMetrics.routeSum.startTimer(),
});
this.createTimers(request);
}

@@ -255,4 +277,6 @@ return done();

};
metrics.sum(labels);
metrics.hist(labels);
if (metrics.hist)
metrics.hist(labels);
if (metrics.sum)
metrics.sum(labels);
done();

@@ -259,0 +283,0 @@ });

@@ -56,6 +56,7 @@ "use strict";

const { name = 'metrics', clearRegisterOnInit = false } = options;
const promClient = options.promClient ?? prom_client_1.default;
if (clearRegisterOnInit) {
prom_client_1.default.register.clear();
promClient.register.clear();
}
const fm = new fastify_metrics_1.FastifyMetrics({ client: prom_client_1.default, fastify, options });
const fm = new fastify_metrics_1.FastifyMetrics({ client: promClient, fastify, options });
fastify.decorate(name, fm);

@@ -62,0 +63,0 @@ }, {

@@ -136,9 +136,19 @@ import { FastifyReply, FastifyRequest, HTTPMethods, RouteOptions } from 'fastify';

export interface IRouteMetricsConfig {
enabled?: boolean | {
/**
* Enables collection of fastify routes metrics response time via
* histogram.
*
* @defaultValue `true`
*/
histogram?: boolean;
/**
* Enables collection of fastify routes metrics response time via
* summary.
*
* @defaultValue `true`
*/
summary?: boolean;
};
/**
* Enables collection of fastify routes metrics response time.
*
* @defaultValue `false`
*/
enabled?: boolean;
/**
* Collect metrics only for registered routes. If `false`, then metrics for

@@ -161,3 +171,3 @@ * unknown routes `/unknown-unregistered-route` will be collected as well.

*/
routeBlacklist?: readonly string[];
routeBlacklist?: readonly (string | RegExp)[];
/**

@@ -201,2 +211,8 @@ * A list of HTTP methods that will be excluded from metrics collection

/**
* PromClient instance to override default internal promClient
*
* @defaultValue promClient
*/
promClient: typeof client | null;
/**
* Endpoint to expose metrics in prometheus format. `null` - disables metrics

@@ -203,0 +219,0 @@ * exposure

{
"$schema": "https://json.schemastore.org/package.json",
"name": "fastify-metrics",
"version": "10.3.3",
"version": "10.6.0",
"description": "Prometheus metrics exporter for Fastify",

@@ -6,0 +6,0 @@ "keywords": [

@@ -13,4 +13,2 @@ # fastify-metrics

[![Codecov](https://img.shields.io/codecov/c/gh/SkeLLLa/fastify-metrics.svg)](https://codecov.io/gh/SkeLLLa/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/fastify-metrics.svg)](https://lgtm.com/projects/g/SkeLLLa/fastify-metrics/)

@@ -139,3 +137,5 @@ [Prometheus](https://prometheus.io/) metrics exporter for Fastify.

| [routeMetrics?](./docs/api/fastify-metrics.imetricspluginoptions.routemetrics.md) | [IRouteMetricsConfig](./docs/api/fastify-metrics.iroutemetricsconfig.md) | `{ enabled: true }` |
| [promClient?](./docs/api/fastify-metrics.imetricspluginoptions.promclient.md) | `prom-client` instance \| null | `null` |
#### Route metrics

@@ -145,3 +145,4 @@

| ------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------- | --------------------------------------- |
| [enabled?](./docs/fastify-metrics.iroutemetricsconfig.enabled.md) | boolean | `true` |
| [enabled?](./docs/fastify-metrics.iroutemetricsconfig.enabled.md) | boolean \| { histogram: boolean, summary: boolean } | `true` |
| [enableSummaries?](./docs/fastify-metrics.iroutemetricsconfig.enablesummaries.md) | boolean | `true` |
| [groupStatusCodes?](./docs/fastify-metrics.iroutemetricsconfig.groupstatuscodes.md) | boolean | `false` |

@@ -153,4 +154,22 @@ | [invalidRouteGroup?](./docs/fastify-metrics.iroutemetricsconfig.invalidroutegroup.md) | string | `'__unknown__'` |

| [customLabels?](./fastify-metrics.iroutemetricsconfig.customlabels.md) | Record<string, string \| ((request: FastifyRequest, reply: FastifyReply) => string)> | `undefined` |
| [routeBlacklist?](./docs/fastify-metrics.iroutemetricsconfig.routeblacklist.md) | readonly string\[\] | `[]` |
| [routeBlacklist?](./docs/fastify-metrics.iroutemetricsconfig.routeblacklist.md) | readonly (string \| RegExp)\[\] | `[]` |
#### Route metrics enabled
The `enabled` configuration option can be either a boolean which enables/disables generation of both histograms and summaries, or it can be set to an object that allows you to pick individually whether you want histograms or summaries to be generated, for example:
```
{
...
routeMetrics: {
enabled: {
histogram: true,
summary: false
}
}
}
```
would result in the library only generating histograms.
##### Route metrics overrides

@@ -212,3 +231,3 @@

The following table shows what metrics will be available in Prometheus. Note suffixes like `_bucket`, `_sum`, `_count` are added automatically.
The following table shows what metrics will be available in Prometheus (subject to the `enabled` configuration option). Note suffixes like `_bucket`, `_sum`, `_count` are added automatically.

@@ -215,0 +234,0 @@ | metric | labels | description |

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

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