Class: Rack::Profilers::Statsd

Inherits:
RequestProfiler show all
Defined in:
lib/rack/profilers/statsd.rb

Constant Summary

Constants inherited from RequestProfiler

RequestProfiler::VERSION

Instance Method Summary collapse

Methods inherited from RequestProfiler

#call, #run_time, #start_time, #start_time=

Constructor Details

#initialize(app, statsd, opts = {}) ⇒ Statsd

Returns a new instance of Statsd.

Examples:

use Rack::Profilers::Statsd, Statsd.new('localhost'), :ignore_path => /^\/assets/

Parameters:

  • statsd (Statsd)

    an instance of your statsd client

  • opts (Hash) (defaults to: {})

    a hash of options

  • :namespace (Hash)

    a customizable set of options

  • :ignore_path (Hash)

    a customizable set of options



15
16
17
# File 'lib/rack/profilers/statsd.rb', line 15

def initialize(app, statsd, opts = {})
  @app, @statsd, @opts = app, statsd, opts
end

Instance Method Details

#handle_results(env, request) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rack/profilers/statsd.rb', line 19

def handle_results(env, request)
  clean_url = Utils::UrlStripper.replace_id(request.path)
  clean_url = clean_url[1..-1].gsub('/', '.')
  namespace = @opts[:namespace] || ''

  @statsd.timing("#{namespace}#{request.request_method}.#{clean_url}", run_time)
end