fastify / fastify/under-pressure
Custom function for process metrics
- Dominant language
- JavaScript
- Stars
- 415
- Forks
- 36
- Avg merge
- 4d 22h
- Merged PRs (30d)
- 1
Description
## 🚀 Feature Proposal
Expose a custom function to gather process metrics.
## Motivation
There are cases in which there's already a module/library that monitors process metrics, for example, to report to `statsd`/`prometeus` and similar platforms. This would allow reusing those modules for a similar task.
## Example
```js
fastify.register(require('under-pressure'), {
maxEventLoopUtilization:0.98,
// This custom function will be bound to the fastify instance
usage() {
const { eventLoopUtilization } = this.customMetrics
return { eventLoopUtilization }
}
})
fastify.get('/', (req, reply) => {
reply.send({ hello: 'world'})
})
fastify.listen(3000, err => {
if (err) throw err
console.log(`server listening on ${fastify.server.address().port}`)
})
```
## Notes
There are a lot of details to figure out here, like defining a way to make sure the object returned by the custom `usage` function is safe to use (i.e., it defines all the properties needed), but I just wanted to start a discussion to understand if it's something this plugin could provide.
Contributor guide
Assessment
This issue has not been assessed yet.