SkeLLLa / fastify-metrics

Prometheus metrics exporter for Fastify
https://savelife.in.ua/en/donate-en/
MIT License
99 stars 33 forks source link

Route pattern for monitoring #69

Closed rafamarqqqs closed 2 years ago

rafamarqqqs commented 2 years ago

I'm trying to use route patterns for monitoring (as it's a Prometheus metrics labels best practice) but I cannot find an option to use the route pattern instead of its values. This is an example of what I'm trying to achieve:

-http_request_duration_seconds_bucket{le="0.005",method="GET",route="/jobs/Op4X46WTqqnCKWgV4q",status_code="404"} 0
+http_request_duration_seconds_bucket{le="0.005",method="GET",route="/jobs/:id",status_code="404"} 0

I'd like to use the url defined when registering a new fastify route, e.g:

  fastify.route({
    method: 'GET',
    url: '/jobs/:id',
    handler: handlers.getIds(),
  });

These are the versions I'm using:

fastify-metrics: ^8.0.0
fastify: ^3.6.0

Is there any way I can configure this?

rafamarqqqs commented 2 years ago

Actually, it seems this is only happening for 404 responses... Is there anything I'm missing?

rafamarqqqs commented 2 years ago

So I guess it's all right, the route I was talking about does not exist hence the 404 and the complete URL description. I'm adding the invalidRouteGroup option to solve this.