Module: XRuntime::Utils
- Defined in:
- lib/x_runtime/utils.rb
Constant Summary collapse
- PROBELATESTFLAG =
"XX-Runtime-Latest"
- PROBEFLAG =
"XX-Runtime"
Class Method Summary collapse
- .array_hashify ⇒ Object
-
.probe(headers = {}) ⇒ Object
for Nginx log: log_format timing ‘$remote_addr - $remote_user [$time_local] “$status” $request “$http_user_agent” ’ ‘upstream_response_time $upstream_response_time ’ ‘msec $msec request_time $request_time probe $upstream_http_xx_runtime’;.
- .to_hash(data) ⇒ Object
Class Method Details
.array_hashify ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/x_runtime/utils.rb', line 11 def array_hashify lambda { |array| hash = Hash.new array.each_slice(2) do |field, value| hash[field] = value end hash } end |
.probe(headers = {}) ⇒ Object
for Nginx log: log_format timing ‘$remote_addr - $remote_user [$time_local] “$status” $request “$http_user_agent” ’
'upstream_response_time $upstream_response_time '
'msec $msec request_time $request_time probe $upstream_http_xx_runtime';
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/x_runtime/utils.rb', line 30 def probe(headers={}) headers[PROBEFLAG] = "0" unless headers[PROBEFLAG] if headers[PROBELATESTFLAG] last_probe = headers[PROBELATESTFLAG].to_f headers[PROBEFLAG] += ",#{"%.03f"%((Time.now.to_f - last_probe)*1000)}ms" headers[PROBEFLAG] += " AR:#{"%.03f"%ActiveRecord::LogSubscriber.runtime}ms" if (defined? ActiveRecord::LogSubscriber) end headers[PROBELATESTFLAG] = Time.now.to_f.to_s end |
.to_hash(data) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/x_runtime/utils.rb', line 4 def to_hash(data) case data when Array array_hashify.call(data) end end |