Class: Metrics::Reporter
- Inherits:
-
Object
- Object
- Metrics::Reporter
- Defined in:
- lib/liquid/metrics/reporter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#duration_unit ⇒ Object
Returns the value of attribute duration_unit.
-
#filter ⇒ Object
Returns the value of attribute filter.
-
#rate_unit ⇒ Object
Returns the value of attribute rate_unit.
Instance Method Summary collapse
- #convert_duration(duration) ⇒ Object
- #convert_rate(rate) ⇒ Object
-
#initialize(registry) ⇒ Reporter
constructor
A new instance of Reporter.
- #report_counter(name, counter) ⇒ Object
- #report_counters ⇒ Object
- #report_gauge(name, gauge) ⇒ Object
- #report_gauges ⇒ Object
- #report_histogram(name, histogram) ⇒ Object
- #report_histograms ⇒ Object
- #report_meter(name, meter) ⇒ Object
- #report_meters ⇒ Object
- #report_timer(name, timer) ⇒ Object
- #report_timers ⇒ Object
- #run ⇒ Object
- #start(period = nil, unit = nil) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(registry) ⇒ Reporter
Returns a new instance of Reporter.
14 15 16 17 18 19 20 |
# File 'lib/liquid/metrics/reporter.rb', line 14 def initialize(registry) @registry = registry @filter = MetricFilter::ALL @executor = Executors.newSingleThreadScheduledExecutor self.rate_unit = TimeUnit::SECONDS self.duration_unit = TimeUnit::MILLISECONDS end |
Instance Attribute Details
#duration_unit ⇒ Object
Returns the value of attribute duration_unit.
12 13 14 |
# File 'lib/liquid/metrics/reporter.rb', line 12 def duration_unit @duration_unit end |
#filter ⇒ Object
Returns the value of attribute filter.
10 11 12 |
# File 'lib/liquid/metrics/reporter.rb', line 10 def filter @filter end |
#rate_unit ⇒ Object
Returns the value of attribute rate_unit.
11 12 13 |
# File 'lib/liquid/metrics/reporter.rb', line 11 def rate_unit @rate_unit end |
Instance Method Details
#convert_duration(duration) ⇒ Object
144 145 146 |
# File 'lib/liquid/metrics/reporter.rb', line 144 def convert_duration(duration) (duration * @duration_factor).round(3) end |
#convert_rate(rate) ⇒ Object
148 149 150 |
# File 'lib/liquid/metrics/reporter.rb', line 148 def convert_rate(rate) (rate * @rate_factor).round(3) end |
#report_counter(name, counter) ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/liquid/metrics/reporter.rb', line 91 def report_counter(name, counter) { type: :counter, name: name, count: counter.count, } end |
#report_counters ⇒ Object
59 60 61 62 63 |
# File 'lib/liquid/metrics/reporter.rb', line 59 def report_counters @registry.counters.each do |name, counter| report_counter(name, counter) end end |
#report_gauge(name, gauge) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/liquid/metrics/reporter.rb', line 83 def report_gauge(name, gauge) { type: :gauge, name: name, value: gauge.value, } end |
#report_gauges ⇒ Object
53 54 55 56 57 |
# File 'lib/liquid/metrics/reporter.rb', line 53 def report_gauges @registry.gauges.each do |name, gauge| report_gauge(name, gauge) end end |
#report_histogram(name, histogram) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/liquid/metrics/reporter.rb', line 99 def report_histogram(name, histogram) snapshot = histogram.snapshot { type: :histogram, name: name, count: histogram.count, min: snapshot.getMin, max: snapshot.getMax, mean: snapshot.getMean, stdev: snapshot.getStdDev, median: snapshot.getMedian, :'95th_percentile' => snapshot.get95thPercentile, } end |
#report_histograms ⇒ Object
65 66 67 68 69 |
# File 'lib/liquid/metrics/reporter.rb', line 65 def report_histograms @registry.histograms.each do |name, histogram| report_histogram(name, histogram) end end |
#report_meter(name, meter) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/liquid/metrics/reporter.rb', line 114 def report_meter(name, meter) { type: :meter, name: name, count: meter.count, mean_rate: convert_rate(meter.getMeanRate), one_minute_rate: convert_rate(meter.getOneMinuteRate), five_minute_rate: convert_rate(meter.getFiveMinuteRate), fifteen_minute_rate: convert_rate(meter.getFifteenMinuteRate), } end |
#report_meters ⇒ Object
71 72 73 74 75 |
# File 'lib/liquid/metrics/reporter.rb', line 71 def report_meters @registry.meters.each do |name, meter| report_meter(name, meter) end end |
#report_timer(name, timer) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/liquid/metrics/reporter.rb', line 126 def report_timer(name, timer) snapshot = timer.snapshot { type: :timer, name: name, min: convert_duration(snapshot.getMin), max: convert_duration(snapshot.getMax), mean: convert_duration(snapshot.getMean), stdev: convert_duration(snapshot.getStdDev), median: convert_duration(snapshot.getMedian), :'95th_percentile' => convert_duration(snapshot.get95thPercentile), mean_rate: convert_rate(timer.getMeanRate), one_minute_rate: convert_rate(timer.getOneMinuteRate), five_minute_rate: convert_rate(timer.getFiveMinuteRate), fifteen_minute_rate: convert_rate(timer.getFifteenMinuteRate), } end |
#report_timers ⇒ Object
77 78 79 80 81 |
# File 'lib/liquid/metrics/reporter.rb', line 77 def report_timers @registry.timers.each do |name, timer| report_timer(name, timer) end end |
#run ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/liquid/metrics/reporter.rb', line 32 def run report_gauges report_counters report_histograms report_meters report_timers rescue => e $log.exception(e) end |
#start(period = nil, unit = nil) ⇒ Object
42 43 44 45 46 |
# File 'lib/liquid/metrics/reporter.rb', line 42 def start(period = nil, unit = nil) period ||= 5 unit ||= TimeUnit::MINUTES @executor.scheduleAtFixedRate(self, period, period, unit) end |
#stop ⇒ Object
48 49 50 51 |
# File 'lib/liquid/metrics/reporter.rb', line 48 def stop @executor.shutdown @executor.awaitTermination(1, TimeUnit::SECONDS) rescue nil end |