class Elementary::Middleware::Statsd

Public Class Methods

new(app, opts={}) click to toggle source

Create a new Statsd middleware for Elementary

@param [Hash] opts Hash of optional parameters @option opts [Lookout::StatsdClient] :client Set to an existing instance of a Lookout::StatsdClient or other object implementing Statsd interface.

# File lib/elementary/middleware/statsd.rb, line 12
def initialize(app, opts={})
  @app = app

  @statsd = opts[:client] || Lookout::StatsdClient.new
end

Public Instance Methods

call(service, rpc_method, *params) click to toggle source
# File lib/elementary/middleware/statsd.rb, line 18
def call(service, rpc_method, *params)
  @statsd.time(metric_name(service.name, rpc_method.method)) do
    @app.call(service, rpc_method, *params)
  end
end
metric_name(service_name, method_name) click to toggle source
# File lib/elementary/middleware/statsd.rb, line 24
def metric_name(service_name, method_name)
  service_name = service_name.gsub('::', '.').downcase
  return "elementary.#{service_name}.#{method_name}"
end