Class: RailsRiemannMiddleware::Duration

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_riemann_middleware/duration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, env, start_time, options = {}) ⇒ Duration

Returns a new instance of Duration.



8
9
10
11
# File 'lib/rails_riemann_middleware/duration.rb', line 8

def initialize(event, env, start_time, options={})
  @event, @env, @start_time = event, env, start_time
  @headers = options.fetch(:headers, [])
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/rails_riemann_middleware/duration.rb', line 6

def env
  @env
end

#eventObject (readonly)

Returns the value of attribute event.



6
7
8
# File 'lib/rails_riemann_middleware/duration.rb', line 6

def event
  @event
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/rails_riemann_middleware/duration.rb', line 6

def headers
  @headers
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



6
7
8
# File 'lib/rails_riemann_middleware/duration.rb', line 6

def start_time
  @start_time
end

Instance Method Details

#messageObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_riemann_middleware/duration.rb', line 17

def message
  end_time = Time.new
  duration = (end_time - start_time)
  msg = {
    :host        => env['HTTP_HOST'],
    :service     => "#{event.app_prefix} request duration".strip,
    :state       => 'info',
    :metric      => duration,
    :tags        => ["duration"],
    :description => Headers.new(env, headers).to_s
  }
  msg
end

#sendObject



13
14
15
# File 'lib/rails_riemann_middleware/duration.rb', line 13

def send
  event << message
end