lib/metricize/forwarder.rb in metricize-0.4.5 vs lib/metricize/forwarder.rb in metricize-0.4.6
- old
+ new
@@ -17,16 +17,16 @@
end
private
def process_metric_queue
- queue = retrieve_queue_contents
- return if queue.empty?
- store_metrics(add_aggregate_info(queue))
- clear_queue
- rescue RuntimeError => e
- log_message "Error: " + e.message, :error
+ with_error_handling do
+ queue = retrieve_queue_contents
+ return if queue.empty?
+ store_metrics(add_aggregate_info(queue))
+ clear_queue
+ end
end
def retrieve_queue_contents
log_message "checking... queue_length=#{queue_length = @redis.llen(@queue_name)}", :info
return [] unless queue_length > 0
@@ -79,11 +79,13 @@
key = [metric.fetch(:name), metric[:source]].join('|')
value_groups[key] ||= []
value_groups[key] << metric[:value]
end
value_groups.each do |key, values|
- print_histogram(key, values)
+ with_error_handling do
+ print_histogram(key, values)
+ end
gauges << add_stat_by_key(key, values.size, '.count').merge(counter_attributes)
gauges << add_stat_by_key(key, values.max, ".max")
gauges << add_stat_by_key(key, values.min, ".min")
[0.25, 0.50, 0.75, 0.95].each do |p|
percentile = values.extend(Stats).calculate_percentile(p)
@@ -116,25 +118,16 @@
"#{name}.min=#{round(values.min, 2)}\n" +
"#{name}.max=#{round(values.max, 2)}\n" +
"#{name}.mean=#{round(values.mean, 2)}\n" +
"#{name}.stddev=#{round(values.standard_deviation, 2)}\n"
log_message(chart_output, :info)
- rescue => e
- log_message("#{e}: Could not print histogram for #{name} with these input values: #{values.inspect}", :error)
end
def add_stat_by_key(key, value, suffix = "")
metric = { :name => key.split('|')[0] + suffix,
:value => value }
metric.merge!(:source => key.split('|')[1]) if key.split('|')[1]
metric
- end
-
- def calculate_percentile(values, percentile)
- return values.first if values.size == 1
- values_sorted = values.sort
- k = (percentile*(values_sorted.length-1)+1).floor - 1
- values_sorted[k]
end
end
end