Class: Rack::Graphite
- Inherits:
-
Object
- Object
- Rack::Graphite
- Defined in:
- lib/rack/graphite.rb,
lib/rack/graphite/version.rb
Constant Summary collapse
- PREFIX =
'requests'- ID_REGEXP =
Handle /123/ or /123
%r{/\d+(/|$)}- ID_REPLACEMENT =
'/id\1'.freeze
- GUID_REGEXP =
Handle /GUID/ or /GUID
%r{/\h{8}-\h{4}-\h{4}-\h{4}-\h{12}(/|$)}- GUID_REPLACEMENT =
'/guid\1'.freeze
- VERSION =
'1.3.0'
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Graphite
constructor
A new instance of Graphite.
- #path_to_graphite(method, path) ⇒ Object
Constructor Details
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/graphite.rb', line 16 def call(env) path = env['PATH_INFO'] || '/' method = env['REQUEST_METHOD'] || 'GET' metric = path_to_graphite(method, path) status, headers, body = nil Lookout::Statsd.instance.timing(metric) do status, headers, body = @app.call(env) end Lookout::Statsd.instance.increment("#{metric}.response.#{status}") return status, headers, body end |
#path_to_graphite(method, path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rack/graphite.rb', line 29 def path_to_graphite(method, path) method = method.downcase if (path.nil?) || (path == '/') || (path.empty?) "#{@prefix}.#{method}.root" else # Replace ' ' => '_', '.' => '-' path = path.tr(' .', '_-') path.gsub!(ID_REGEXP, ID_REPLACEMENT) path.gsub!(GUID_REGEXP, GUID_REPLACEMENT) path.tr!('/', '.') "#{@prefix}.#{method}#{path}" end end |