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 1.1.0 to 2.0.0

16

CHANGELOG.md

@@ -5,2 +5,18 @@ # Change Log

<a name="2.0.0"></a>
# [2.0.0](https://gitlab.com/m03geek/fastify-metrics/compare/v1.1.0...v2.0.0) (2018-10-02)
### Features
* **metrics:** add metric default customization ([c7a74b9](https://gitlab.com/m03geek/fastify-metrics/commit/c7a74b9))
* **metrics:** remove count and rename histogram ([9cc92e4](https://gitlab.com/m03geek/fastify-metrics/commit/9cc92e4))
### BREAKING CHANGES
* **metrics:** Histogram metric new name http_request_duration_seconds
<a name="1.1.0"></a>

@@ -7,0 +23,0 @@ # [1.1.0](https://gitlab.com/m03geek/fastify-metrics/compare/v1.0.1...v1.1.0) (2018-09-28)

42

lib/index.js

@@ -8,2 +8,3 @@ const fp = require('fastify-plugin');

enableDefaultMetrics = true,
pluginName = 'metrics',
interval = 5000,

@@ -13,2 +14,3 @@ register,

endpoint,
metrics = {},
} = {},

@@ -21,9 +23,4 @@ next

const opts = {
count: {
name: 'http_request_count',
help: 'request count',
labelNames: ['status_code', 'method', 'route'],
},
hist: {
name: 'http_request_buckets_seconds',
histogram: {
name: 'http_request_duration_seconds',
help: 'request duration in seconds',

@@ -33,3 +30,3 @@ labelNames: ['status_code', 'method', 'route'],

},
sum: {
summary: {
name: 'http_request_summary_seconds',

@@ -41,18 +38,22 @@ help: 'request duration in seconds summary',

};
if (register) {
defaultOpts.register = register;
opts.count.registers = register;
opts.hist.registers = register;
opts.sum.registers = register;
opts.histogram.registers = register;
opts.summary.registers = register;
}
if (prefix) {
defaultOpts.prefix = prefix;
opts.count.name = `${prefix}${opts.count.name}`;
opts.hist.name = `${prefix}${opts.count.name}`;
opts.sum.name = `${prefix}${opts.count.name}`;
opts.histogram.name = `${prefix}${opts.count.name}`;
opts.summary.name = `${prefix}${opts.count.name}`;
}
Object.keys(metrics).filter(opts.hasOwnProperty).forEach((key)=>{
Object.assign(opts[key], metrics[key]);
});
client.collectDefaultMetrics(defaultOpts);
const routeCount = new client.Counter(opts.count);
const routeHist = new client.Histogram(opts.hist);
const routeSum = new client.Summary(opts.sum);
const routeHist = new client.Histogram(opts.histogram);
const routeSum = new client.Summary(opts.summary);

@@ -97,7 +98,2 @@ if (endpoint) {

});
routeCount.inc({
method,
route: routeId,
status_code: reply.res.statusCode,
});

@@ -107,3 +103,3 @@ next();

}
fastify.decorate('metrics', plugin);
fastify.decorate(pluginName, plugin);
next();

@@ -110,0 +106,0 @@ };

{
"name": "fastify-metrics",
"version": "1.1.0",
"version": "2.0.0",
"description": "Prometheus metrics exporter for Fastify",

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

@@ -29,2 +29,3 @@ # fastify-metrics

- [Plugin options](#plugin-options)
- [Metrics details](#metrics-details)
- [HTTP routes metrics](#http-routes-metrics)

@@ -79,2 +80,3 @@ - [See also](#see-also)

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

@@ -84,3 +86,46 @@ | `register` | Object | Custom prom-client metrics registry (see [docs](https://github.com/siimon/prom-client#default-metrics)). | `undefined` |

| `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. | `{}` |
#### Metrics details
You may override default metrics settings. You may provide overrides for two metrics tracking http request durations: `histogram` and `summary`.
Default values:
```js
{
histogram: {
name: 'http_request_duration_seconds',
help: 'request duration in seconds',
labelNames: ['status_code', 'method', 'route'],
buckets: [0.005, 0.05, 0.1, 0.5, 1, 3, 5, 10],
},
summary: {
name: 'http_request_summary_seconds',
help: 'request duration in seconds summary',
labelNames: ['status_code', 'method', 'route'],
percentiles: [0.5, 0.9, 0.95, 0.99],
},
}
```
You may also provide registers there or use it instead of prefix. Override should look like:
```js
const fastify = require('fastify');
const app = fastify();
const metricsPlugin = require('fastify-metrics');
app.register(metricsPlugin, {endpoint: '/metrics', {
histogram: {
name: 'my_custom_http_request_duration_seconds',
buckets: [0.1, 0.5, 1, 3, 5],
},
summary: {
help: 'custom request duration in seconds summary help',
labelNames: ['status_code', 'method', 'route'],
percentiles: [0.5, 0.75, 0.9, 0.95, 0.99],
},
}});
```
<sub>[Back to top](#toc)</sub>

@@ -90,3 +135,2 @@

| metric | labels | description |

@@ -93,0 +137,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