discourse / prometheus_exporter

A framework for collecting and aggregating prometheus metrics
MIT License
532 stars 154 forks source link

puma/sinatra/multi-process/middleware & paths #45

Open Eric-Fontana-Bose opened 5 years ago

Eric-Fontana-Bose commented 5 years ago

I'm using puma with sinatra and puma clustered mode. I added a

use PrometheusExporter::Middleware

And I am seeing

# HELP ruby_http_requests A counter of HTTP requests made
# TYPE ruby_http_requests counter
ruby_http_requests{path="/discover/product/123"} 2
ruby_http_requests{path="/discover/product/456"} 1

However, I don't want my metrics to record every product number, I want it to record it like:

ruby_http_requests{path="/discover/product/:id"} 

Is this possible? How do I modify the path

The client_ruby library which I switched away from has a way to do this.

SamSaffron commented 5 years ago

Yeah path is ultra weak, this is why our default rails middleware tries to send action and controller name per:

https://github.com/discourse/prometheus_exporter/blob/master/lib/prometheus_exporter/middleware.rb#L42-L49

Do you have a access to action/controller name in env in Sinatra?

Also I search our codebase and can not see where we are reporting path..

Eric-Fontana-Bose commented 5 years ago

yes, I have access to them, not sure what to do about it though?

ideally, this is what I want:

{@env["sinatra.route"]}"

https://stackoverflow.com/questions/40978705/get-sinatra-request-route-path

SamSaffron commented 5 years ago

A PR to improve our middleware is the way to go:

route = nil

if params action = params["action"] controller = params["controller"] else
route = env["sinatra.route"] end