Gathering detailed insights and metrics for fastify-metrics
Gathering detailed insights and metrics for fastify-metrics
Gathering detailed insights and metrics for fastify-metrics
Gathering detailed insights and metrics for fastify-metrics
@platformatic/fastify-http-metrics
The `fastify-http-metrics` package provides a simple way to collect prometheus metrics for your Fastify application.
fastify-metrics-js-prometheus
A Fastify plugin for consuming @metrics/client (https://www.npmjs.com/package/@metrics/client) streams and rendering a prometheus scraping page
fastify-metrics-js-response-timing
A Fastify plugin using @metrics/client (https://www.npmjs.com/package/@metrics/client) to produce metric streams reporting metrics about route response times
@immobiliarelabs/fastify-metrics
A minimalistic and opinionated Fastify plugin that collects metrics and dispatches them to statsd
npm install fastify-metrics
Typescript
Module System
Node Version
NPM Version
87.2
Supply Chain
98.2
Quality
77.2
Maintenance
100
Vulnerability
100
License
TypeScript (87.96%)
JavaScript (12.04%)
Total Downloads
12,133,026
Last Day
1,265
Last Week
50,970
Last Month
235,276
Last Year
4,484,264
MIT License
109 Stars
296 Commits
33 Forks
3 Watchers
2 Branches
23 Contributors
Updated on May 29, 2025
Minified
Minified + Gzipped
Latest Version
12.1.0
Package Id
fastify-metrics@12.1.0
Unpacked Size
53.16 kB
Size
13.83 kB
File Count
14
NPM Version
10.8.3
Node Version
22.9.0
Published on
Sep 20, 2024
Cumulative downloads
Total Downloads
Last Day
-17.1%
1,265
Compared to previous day
Last Week
-9.7%
50,970
Compared to previous week
Last Month
-11.6%
235,276
Compared to previous month
Last Year
-18.6%
4,484,264
Compared to previous year
2
1
41
Prometheus metrics exporter for Fastify.
This plugin uses prom-client under the hood.
This plugin also adds two http metrics for your routes:
fastify-1.x
fastify-2.x
prom-client-11.x
fastify-2.x
prom-client-12.x
fastify-3.x
fastify-4.x
prom-client-14.x
context.config
with routeConfig
due to deprecation in fastify v4 and removal in fastify v5. If you had disableMetrics
option in you route config
, update fastify to latest version.request.routeOptions.method
over deprecated request.routerMethod
.metrics
from request
. Now it uses WeakMap
and not exposed.enableDefaultMetrics
- now enables only default prom-client
metrics. Set to true
by default.enableRouteMetrics
- additional flag that enables route metrics. Set to true
by default.1npm i fastify-metrics --save 2pnpm i fastify-metrics --save
metrics
to fastify instance for your custom metrics.>=4.0.0
.>=18.0.0
.Add it to your project like regular fastify plugin. Use register
method and pass options to it.
1const fastify = require('fastify'); 2const app = fastify(); 3 4const metricsPlugin = require('fastify-metrics'); 5await app.register(metricsPlugin, { endpoint: '/metrics' });
It also exports client to fastify instance fastify.metrics.client
which you may use it in your routes.
You may create your metrics when app starts and store it in fastify.metrics
object and reuse them in multiple routes.
After calling registry.clear()
all metrics are removed from registry. In order to add them again to the registry, call fastify.mterics.initMetricsInRegistry
.
See for details docs
Property | Type | Default Value |
---|---|---|
defaultMetrics? | IDefaultMetricsConfig | { enabled: true } |
endpoint? | string | null | Fastify.RouteOptions | '/metrics' |
name? | string | 'metrics' |
routeMetrics? | IRouteMetricsConfig | { enabled: true } |
promClient? | prom-client instance | null | null |
Property | Type | Default Value |
---|---|---|
enabled? | boolean | { histogram: boolean, summary: boolean } | true |
enableSummaries? | boolean | true |
groupStatusCodes? | boolean | false |
invalidRouteGroup? | string | '__unknown__' |
methodBlacklist? | readonly string[] | ['HEAD','OPTIONS','TRACE','CONNECT',] |
overrides? | IRouteMetricsOverrides | |
registeredRoutesOnly? | boolean | true |
customLabels? | Record<string, string | ((request: FastifyRequest, reply: FastifyReply) => string)> | undefined |
routeBlacklist? | readonly (string | RegExp)[] | [] |
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.
You may override default metrics settings. You may provide overrides for two metrics tracking http request durations: histogram
and summary
.
1const fastify = require('fastify'); 2const app = fastify(); 3const metricsPlugin = require('fastify-metrics'); 4 5await app.register(metricsPlugin, { 6 endpoint: '/metrics', 7 routeMetrics: { 8 overrides: { 9 histogram: { 10 name: 'my_custom_http_request_duration_seconds', 11 buckets: [0.1, 0.5, 1, 3, 5], 12 }, 13 summary: { 14 help: 'custom request duration in seconds summary help', 15 labelNames: ['status_code', 'method', 'route'], 16 percentiles: [0.5, 0.75, 0.9, 0.95, 0.99], 17 }, 18 }, 19 }, 20});
Property | Type | Default value |
---|---|---|
getRouteLabel? | (request: FastifyRequest) => string | undefined |
method? | string | 'method' |
route? | string | 'route' |
status? | string | 'status_code' |
Property | Type | Default value |
---|---|---|
name? | string | 'http_request_summary_seconds' |
help? | string | 'request duration in seconds summary' |
percentiles? | number[] | [0.5, 0.9, 0.95, 0.99] |
Property | Type | Default value |
---|---|---|
name? | string | 'http_request_duration_seconds' |
help? | string | 'request duration in seconds' |
buckets? | number[] | [0.05, 0.1, 0.5, 1, 3, 5, 10] |
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.
metric | labels | description |
---|---|---|
http_request_duration_seconds_count | method , route , status_code | Requests total count |
http_request_duration_seconds_bucket | method , route , status_code | Requests durations by bucket |
http_request_summary_seconds | method , route , status_code | Requests duration percentiles |
http_request_summary_seconds_count | method , route , status_code | Requests total count |
See docs.
See changelog.
Licensed under MIT.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool detected but not run on all commits
Details
Reason
Found 7/24 approved changesets -- score normalized to 2
Reason
0 commit(s) and 2 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
10 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More