https://github.com/fastify/fastify-routes-stats
provide stats for routes using perf_hooks, for fastify
https://github.com/fastify/fastify-routes-stats
fastify fastify-plugin
Last synced: 2 months ago
JSON representation
provide stats for routes using perf_hooks, for fastify
- Host: GitHub
- URL: https://github.com/fastify/fastify-routes-stats
- Owner: fastify
- License: mit
- Created: 2018-03-23T14:54:57.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2025-03-07T19:12:49.000Z (3 months ago)
- Last Synced: 2025-03-29T09:08:24.090Z (2 months ago)
- Topics: fastify, fastify-plugin
- Language: JavaScript
- Homepage: https://npmjs.com/package/@fastify/routes-stats
- Size: 127 KB
- Stars: 50
- Watchers: 16
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @fastify/routes-stats
[](https://github.com/fastify/fastify-routes-stats/actions/workflows/ci.yml)
[](https://www.npmjs.com/package/@fastify/routes-stats)
[](https://github.com/neostandard/neostandard)Provide stats for routes using `require('node:perf_hooks')`, for **Fastify**.
## Install
```sh
npm i @fastify/routes-stats
```## Example
```js
'use strict'const Fastify = require('fastify')
const fastify = Fastify()fastify.register(require('@fastify/routes-stats'), {
printInterval: 4000, // milliseconds
decoratorName: "performanceMarked", // decorator is set to true if a performance.mark was called for the request
})fastify.get('/', function (request, reply) {
reply.send({ hello: 'world' })
})fastify.get(
'/:param/dynamic-route-example',
{ config: { statsId: 'group-stats-together' } },
function (request, reply) {
reply.send({ hello: 'world' })
}
)fastify.get('/__stats__', async function () {
// stats is added to the fastify instance
return this.stats()
})fastify.listen({ port: 3000 })
``````sh
$ curl -s localhost:3000/__stats__ | jsonlint
{
"GET": {
"/": {
"mean": 0.2406786,
"mode": 0.755647,
"median": 0.121999,
"max": 0.755647,
"min": 0.050214,
"sd": 0.2905856386253457
}
},
"POST": {
"/": {
"mean": 0.11260519999999999,
"mode": 0.292262,
"median": 0.055179,
"max": 0.292262,
"min": 0.044159,
"sd": 0.10438752062722824
}
}
}
```It will also log a stat object every 30 seconds (by default).
## License
MIT