Class: Dalia::MiniGraphite::RoutesReporter
- Inherits:
-
Object
- Object
- Dalia::MiniGraphite::RoutesReporter
- Defined in:
- lib/mini_graphite/routes_reporter.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, &routes_block) ⇒ RoutesReporter
constructor
A new instance of RoutesReporter.
Constructor Details
#initialize(app, &routes_block) ⇒ RoutesReporter
Returns a new instance of RoutesReporter.
4 5 6 7 8 |
# File 'lib/mini_graphite/routes_reporter.rb', line 4 def initialize(app, &routes_block) @app = app @routes = {} instance_eval(&routes_block) if block_given? end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mini_graphite/routes_reporter.rb', line 10 def call(env) start_time = Time.now status, headers, body = @app.call(env) time_taken = (1000 * (Time.now - start_time)) current_route = env["sinatra.route"] route = @routes.select { |graphite_key, route_regexp| current_route =~ route_regexp} if route graphite_key = route.keys.first Dalia::MiniGraphite.counter("#{graphite_key}.count") if graphite_key Dalia::MiniGraphite.counter("#{graphite_key}.duration", time_taken) if graphite_key Dalia::MiniGraphite.time("#{graphite_key}.duration_stats", time_taken) if graphite_key end [status, headers, body] end |