Class: Rack::Perf
- Inherits:
-
Object
- Object
- Rack::Perf
- Defined in:
- lib/rack/perf.rb,
lib/rack/perf/version.rb
Constant Summary collapse
- VERSION =
"1.1.2"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(stack, api_key, debug = false) ⇒ Perf
constructor
A new instance of Perf.
Constructor Details
#initialize(stack, api_key, debug = false) ⇒ Perf
Returns a new instance of Perf.
17 18 19 20 21 |
# File 'lib/rack/perf.rb', line 17 def initialize(stack, api_key, debug = false) @stack = stack @api_key = api_key @debug = debug end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rack/perf.rb', line 23 def call(env) @env = env # log the current time now before the request starts @starttime = Time.now # run the current request request = Rack::Request.new(env) @status, @headers, @body = stack.call(env) # log the end time of the request @endtime = Time.now # get all extra information that we need for logging # that request to Perf ip_addr = request.ip ip_addr = env["HTTP_X_FORWARDED_FOR"] if env["HTTP_X_FORWARDED_FOR"] normalized_uri = get_normalized_path(request) # send it up as long as we don't get nil, this helps # in cases when we intercept asset urls that don't # really matter if normalized_uri send_data(request.ip, request.request_method, request.url, normalized_uri, status, runtime) end # send back intended data [status, headers, body] end |