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.
24 25 26 27 28 29 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 24 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.
22 23 24 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 22 def graphite_host @graphite_host end |
#graphite_port ⇒ Object
Returns the value of attribute graphite_port.
22 23 24 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 22 def graphite_port @graphite_port end |
#namespace ⇒ Object
Returns the value of attribute namespace.
22 23 24 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 22 def namespace @namespace end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 39 def call(env) # Try to build up a path for the STATSD logging if env[:saddle][:statsd_path] statsd_path = env[:saddle][:statsd_path] elsif env[:saddle][:client] statsd_path_components = [ 'saddle', env[:saddle][:client].name.underscore, ] if env[:saddle][:call_chain] && env[:saddle][:action] statsd_path_components += env[:saddle][:call_chain] statsd_path_components << env[:saddle][:action] else statsd_path_components << 'raw' statsd_path_components << "#{env[:url].host}#{env[:url].path}" end statsd_path = statsd_path_components.join('.') end # If we have a path, wrap the call if statsd_path self.statsd.time(sanitize_path(statsd_path)) do @app.call(env) end else @app.call(env) end end |
#statsd ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/saddle/middleware/logging/statsd.rb', line 31 def statsd @statsd ||= begin client = ::Statsd.new(@graphite_host, @graphite_port) client.namespace = @namespace if @namespace client end end |