SkeLLLa/fastify-metrics

Docs for custom metrics

Closed this issue · 3 comments

Hi, thanks for your amazing repo!

I would like to gather some custom metrics but I didn't find some tests that describe this kind of feature. Is it possible to add a custom gauge to prom-client. If yes, how?

I can send you a PR if needed.

Yes, it's possible. Plugin expose client which is standard instance of prom-client. So you can use it just as usual prom-client. Try it out fastify.metrics.client. If it works, then we can add more detailed docs.

Actually there are few docs in https://github.com/SkeLLLa/fastify-metrics/blob/master/docs/interfaces/_fastify_.fastifyinstance.md#metrics, but it requires to go deeper to discover what's in there.

wyozi commented

Custom metrics seem to just work when you create them using the FastifyInstance client.

const socketGauge = new fastify.metrics.client.Gauge({
  name: 'notification_sockets_open',
  help: 'Number of notification websockets open',
  collect() {
    this.set(sockets.length)
  }
})

comment deleted. false alarm.