fastify / fastify/under-pressure

Custom function for process metrics

Open
#81 6 comments 0 reactions 0 assignees View on GitHub
enhancement
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.