Class: Metriksd::LibratoMetricsReporter::TimesliceRollup

Inherits:
Object
  • Object
show all
Defined in:
lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb

Defined Under Namespace

Classes: AverageGauge, SumGauge

Instance Method Summary collapse

Constructor Details

#initialize(timeslice) ⇒ TimesliceRollup

Returns a new instance of TimesliceRollup.



65
66
67
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 65

def initialize(timeslice)
  @timeslice = timeslice
end

Instance Method Details

#add_counter(data) ⇒ Object



101
102
103
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 101

def add_counter(data)
  average_gauge(data.name, data[:source], data[:count])
end

#add_gauge(data) ⇒ Object



105
106
107
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 105

def add_gauge(data)
  average_gauge(data.name, data[:source], data[:value])
end

#add_histogram(data) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 142

def add_histogram(data)
  # average_gauge(data.name + '.mean', data[:source], data[:mean])

  if data[:median]
    average_gauge(data.name + '.median', data[:source], data[:median])
  end

  if data["95th_percentile"]
    average_gauge(data.name + '.95th_percentile', data[:source], data["95th_percentile"])
  end
end

#add_meter(data) ⇒ Object



138
139
140
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 138

def add_meter(data)
  sum_gauge(data.name, data[:source], data[:one_minute_rate])
end

#add_timer(data) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 109

def add_timer(data)
  # average_gauge(data.name + '.mean', data[:source], data[:mean])

  sum_gauge(data.name + '.one_minute_rate', data[:source], data[:one_minute_rate])

  if data[:median]
    average_gauge(data.name + '.median', data[:source], data[:median])
  end

  if data["95th_percentile"]
    average_gauge(data.name + '.95th_percentile', data[:source], data["95th_percentile"])
  end
end

#add_utilization_timer(data) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 123

def add_utilization_timer(data)
  # average_gauge(data.name + '.mean', data[:source], data[:mean])

  sum_gauge(data.name + '.one_minute_rate', data[:source], data[:one_minute_rate])
  average_gauge(data.name + '.one_minute_utilization', data[:source], data[:one_minute_utilization])

  if data[:median]
    average_gauge(data.name + '.median', data[:source], data[:median])
  end

  if data["95th_percentile"]
    average_gauge(data.name + '.95th_percentile', data[:source], data["95th_percentile"])
  end
end

#average_gauge(name, source, value) ⇒ Object



154
155
156
157
158
159
160
161
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 154

def average_gauge(name, source, value)
  # Deal with cases where we get things that aren't numbers
  return unless value.is_a?(Numeric)

  key = [ name, source ].join('/')
  @gauges[key] ||= AverageGauge.new(name, source)
  @gauges[key].mark(value)
end

#processObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 69

def process
  return if @gauges
  @gauges = {}

  @timeslice.flush.each do |data|
    case data[:type]
    when 'counter'
      add_counter(data)
    when 'timer'
      add_timer(data)
    when 'utilization_timer'
      add_utilization_timer(data)
    when 'meter'
      add_meter(data)
    when 'histogram'
      add_histogram(data)
    when 'gauge'
      add_gauge(data)
    else
      puts "Unknown data type: #{data[:type].inspect}"
    end
  end
end

#sum_gauge(name, source, value) ⇒ Object



163
164
165
166
167
168
169
170
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 163

def sum_gauge(name, source, value)
  # Deal with cases where we get things that aren't numbers
  return unless value.is_a?(Numeric)

  key = [ name, source ].join('/')
  @gauges[key] ||= SumGauge.new(name, source)
  @gauges[key].mark(value)
end

#to_hashObject



93
94
95
96
97
98
99
# File 'lib/metriksd/librato_metrics_reporter/timeslice_rollup.rb', line 93

def to_hash
  process

  @gauges.map do |name, gauge|
    [ gauge.name, gauge.to_hash.merge(:measure_time => @timeslice.time) ]
  end
end