Class: InstStatsd::RequestStat

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

Instance Attribute Summary

Attributes inherited from BlockStat

#short_stat, #stats, #tags

Instance Method Summary collapse

Methods inherited from BlockStat

#exclusive_stats, #subtract_exclusives

Constructor Details

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

Returns a new instance of RequestStat.



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

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

Instance Method Details

#action ⇒ Object



45
46
47
# File 'lib/inst_statsd/request_stat.rb', line 45

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

#common_key ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/inst_statsd/request_stat.rb', line 13

def common_key
  common_key = super
  return common_key if common_key
  if @statsd.data_dog?
    self.common_key = "request"
    self.short_stat = "request"
    self.tags[:controller] = controller if controller
    self.tags[:action] = action if action
  else
    self.common_key = "request.#{controller}.#{action}" if controller && action
  end
end

#controller ⇒ Object



41
42
43
# File 'lib/inst_statsd/request_stat.rb', line 41

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

#db_runtime ⇒ Object



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

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

#report ⇒ Object



26
27
28
29
30
31
# File 'lib/inst_statsd/request_stat.rb', line 26

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

#total ⇒ Object



49
50
51
52
53
54
# File 'lib/inst_statsd/request_stat.rb', line 49

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

#view_runtime ⇒ Object



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

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