Class: Protobuf::Rpc::Middleware::Statsd

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/protobuf/rpc/middleware/statsd.rb

Instance Method Summary collapse

Methods included from Logging

initialize_logger, #log_exception, #log_signature, #logger, #sign_message

Constructor Details

#initialize(app) ⇒ Statsd

Returns a new instance of Statsd.



9
10
11
# File 'lib/protobuf/rpc/middleware/statsd.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/protobuf/rpc/middleware/statsd.rb', line 13

def call(env)
  start_time = Time.now.utc
  begin
    env = @app.call(env)
  ensure
    record_stats(env, start_time)
  end

  env
end

#statsd_base_path(env) ⇒ Object

Return base path for StatsD metrics



25
26
27
28
29
# File 'lib/protobuf/rpc/middleware/statsd.rb', line 25

def statsd_base_path(env)
  if env.service_name && env.method_name
    "rpc-server.#{env.service_name}.#{env.method_name}".gsub('::', '.').downcase
  end
end