Skip to content

Instantly share code, notes, and snippets.

@daveyeu
Created February 6, 2013 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save daveyeu/e2f9cc33c3e407dbc6fc to your computer and use it in GitHub Desktop.
Save daveyeu/e2f9cc33c3e407dbc6fc to your computer and use it in GitHub Desktop.
Calculating X-Queue-Time for New Relic instrumentation
now = Time.now.to_f
milliseconds = (now * 1000).to_i
microseconds = (now * 1000000).to_i
env["HTTP_X_MIDDLEWARE_START"] = "t=#{microseconds}"
if env["HTTP_X_REQUEST_START"]
request_start_milliseconds = env["HTTP_X_REQUEST_START"].to_i
request_start_microseconds = request_start_milliseconds * 1000
queue_time_milliseconds = milliseconds - request_start_milliseconds
queue_time_microseconds = microseconds - request_start_microseconds
env["HTTP_X_QUEUE_TIME"] = "t=#{queue_time_microseconds}"
statsd.measure("heroku.router_to_rack", queue_time_milliseconds)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment