Sha256: 1c6cae5e31e8bbf6a62e5ed4fa4c1a24f25ad3b7a556f28c2bb008c24e5dc7bc
Contents?: true
Size: 1.21 KB
Versions: 2
Compression:
Stored size: 1.21 KB
Contents
require 'lookout/statsd' module Rack class Graphite PREFIX = 'requests' ID_REGEXP = %r{/\d+(/|$)} # Handle /123/ or /123 ID_REPLACEMENT = '/id\1'.freeze GUID_REGEXP = %r{/\h{8}-\h{4}-\h{4}-\h{4}-\h{12}(/|$)} # Handle /GUID/ or /GUID GUID_REPLACEMENT = '/guid\1'.freeze def initialize(app, options={}) @app = app @prefix = options[:prefix] || PREFIX end 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.time(metric) do status, headers, body = @app.call(env) end Lookout::Statsd.instance.increment("#{metric}.response.#{status}") return status, headers, body end 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rack-graphite-1.4.1 | lib/rack/graphite.rb |
rack-graphite-1.4.0 | lib/rack/graphite.rb |