Class: SenorArmando::Rack::StatsdLogger

Inherits:
Object
  • Object
show all
Includes:
Goliath::Rack::AsyncMiddleware
Defined in:
lib/senor_armando/rack/statsd_logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, name = nil) ⇒ StatsdLogger

Returns a new instance of StatsdLogger.



8
9
10
11
# File 'lib/senor_armando/rack/statsd_logger.rb', line 8

def initialize app, name=nil
  @name = name || Settings.statsd_name
  super(app)
end

Instance Method Details

#agentObject



24
25
26
# File 'lib/senor_armando/rack/statsd_logger.rb', line 24

def agent
  Goliath::Plugin::StatsdPlugin.agent
end

#call(env) ⇒ Object



13
14
15
16
# File 'lib/senor_armando/rack/statsd_logger.rb', line 13

def call(env)
  agent.count [@name, :req, route(env)] if agent
  super(env)
end

#post_process(env, status, headers, body) ⇒ Object



18
19
20
21
22
# File 'lib/senor_armando/rack/statsd_logger.rb', line 18

def post_process(env, status, headers, body)
  agent.timing([@name, :req_time, route(env)], (1000 * (Time.now.to_f - env[:start_time].to_f))) if agent
  agent.timing([@name, :req_time, status],     (1000 * (Time.now.to_f - env[:start_time].to_f))) if agent
  [status, headers, body]
end

#route(env) ⇒ Object



28
29
30
31
32
# File 'lib/senor_armando/rack/statsd_logger.rb', line 28

def route(env)
  path = env['PATH_INFO'].gsub(%r{^/}, '')
  return 'root' if path == ''
  path.gsub(%r{/}, '.')
end