class Takwimu::Periodic
The periodic class is used to send occasional metrics to a reporting instance of `Barnes::Reporter` at a semi-regular rate.
Public Class Methods
new(reporter:, sample_rate: 1, panels: [])
click to toggle source
# File lib/takwimu/periodic.rb, line 34 def initialize(reporter:, sample_rate: 1, panels: []) @reporter = reporter @reporter.sample_rate = sample_rate @default_interval = 5.0 # compute interval based on a 60s reporting phase. @interval = sample_rate * @default_interval @panels = panels @thread = Thread.new { Thread.current[:takwimu_state] = {} @panels.each do |panel| panel.start! Thread.current[:takwimu_state] end loop do begin sleep @interval # read the current values env = { STATE => Thread.current[:takwimu_state], COUNTERS => {}, GAUGES => {}, TIMERS => {} } @panels.each do |panel| panel.instrument! env[STATE], env[COUNTERS], env[GAUGES], env[TIMERS] end @reporter.report env end end } @thread.abort_on_exception = true end
Public Instance Methods
stop()
click to toggle source
# File lib/takwimu/periodic.rb, line 73 def stop @thread.exit end