Class: CanvasStatsd::RequestStat

Inherits:
BlockStat show all
Defined in:
lib/canvas_statsd/request_stat.rb

Instance Attribute Summary

Attributes inherited from BlockStat

#stats

Instance Method Summary collapse

Methods inherited from BlockStat

#exclusive_stats, #subtract_exclusives

Constructor Details

#initialize(name, start, finish, id, payload, statsd = CanvasStatsd::Statsd) ⇒ RequestStat

Returns a new instance of RequestStat.



3
4
5
6
7
8
9
10
# File 'lib/canvas_statsd/request_stat.rb', line 3

def initialize(name, start, finish, id, payload, statsd=CanvasStatsd::Statsd)
  super(nil, statsd)
  @name = name
  @start = start
  @finish = finish
  @id = id
  @payload = payload
end

Instance Method Details

#actionObject



37
38
39
# File 'lib/canvas_statsd/request_stat.rb', line 37

def action
  @payload.fetch(:params, {})['action']
end

#common_keyObject



12
13
14
15
16
# File 'lib/canvas_statsd/request_stat.rb', line 12

def common_key
  common_key = super
  return common_key if common_key
  self.common_key = "request.#{controller}.#{action}" if controller && action
end

#controllerObject



33
34
35
# File 'lib/canvas_statsd/request_stat.rb', line 33

def controller
  @payload.fetch(:params, {})['controller']
end

#db_runtimeObject



25
26
27
# File 'lib/canvas_statsd/request_stat.rb', line 25

def db_runtime
  @payload.fetch(:db_runtime, nil)
end

#reportObject



18
19
20
21
22
23
# File 'lib/canvas_statsd/request_stat.rb', line 18

def report
  stats['total'] = total
  stats['view'] = view_runtime if view_runtime
  stats['db'] = db_runtime if db_runtime
  super
end

#totalObject



41
42
43
44
45
46
# File 'lib/canvas_statsd/request_stat.rb', line 41

def total
  if (!@finish || !@start)
    return 0
  end
  (@finish - @start) * 1000
end

#view_runtimeObject



29
30
31
# File 'lib/canvas_statsd/request_stat.rb', line 29

def view_runtime
  @payload.fetch(:view_runtime, nil)
end