Class: Saddle::Middleware::Logging::StatsdLogger
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Saddle::Middleware::Logging::StatsdLogger
- Defined in:
- lib/saddle/middleware/logging/statsd.rb
Overview
Public: Wraps request with statsd logging Expects statsd_path in request options. However, if using saddle and no statsd_path is specified will read call_chain and action and use them to construct a statsd_path
Instance Attribute Summary collapse
-
#graphite_host ⇒ Object
Returns the value of attribute graphite_host.
-
#graphite_port ⇒ Object
Returns the value of attribute graphite_port.
-
#namespace ⇒ Object
Returns the value of attribute namespace.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, graphite_host, graphite_port = nil, namespace = nil) ⇒ StatsdLogger
constructor
A new instance of StatsdLogger.
- #statsd ⇒ Object
Constructor Details
#initialize(app, graphite_host, graphite_port = nil, namespace = nil) ⇒ StatsdLogger
Returns a new instance of StatsdLogger.
17 18 19 20 21 22 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 17 def initialize(app, graphite_host, graphite_port=nil, namespace=nil) super(app) @graphite_host = graphite_host @graphite_port = graphite_port @namespace = namespace end |
Instance Attribute Details
#graphite_host ⇒ Object
Returns the value of attribute graphite_host.
15 16 17 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 15 def graphite_host @graphite_host end |
#graphite_port ⇒ Object
Returns the value of attribute graphite_port.
15 16 17 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 15 def graphite_port @graphite_port end |
#namespace ⇒ Object
Returns the value of attribute namespace.
15 16 17 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 15 def namespace @namespace end |
Instance Method Details
#call(env) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 32 def call(env) # Try to build up a path for the STATSD logging if env[:request][:statsd_path] statsd_path = env[:request][:statsd_path] elsif env[:request][:saddle] statsd_path = ( ['saddle'] + [env[:request][:saddle][:client_name]] + env[:request][:saddle][:call_chain] + [env[:request][:saddle][:action]] ).join('.') else statsd_path = "saddle.raw.#{env[:host].to_s}.#{env[:path].to_s}" end # If we have a path, wrap the ensuing app call in STATSD timing if statsd_path self.statsd.time(statsd_path) do @app.call(env) end else @app.call(env) end end |
#statsd ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 24 def statsd @statsd ||= begin client = ::Statsd.new(@graphite_host, @graphite_port) client.namespace = @namespace if @namespace client end end |