class ElasticAPM::Metrics::Collector
@api private
def collect
def collect MUTEX.synchronize do samplers.each_with_object({}) do |sampler, samples| next unless (sample = sampler.collect) samples.merge!(sample) end end end
def collect_and_send
def collect_and_send metricset = Metricset.new(tags: tags, **collect) return if metricset.empty? callback.call(metricset) end
def initialize(config, tags: nil, &block)
def initialize(config, tags: nil, &block) @config = config @tags = tags @samplers = [CpuMem].map { |kls| kls.new(config) } @callback = block end
def running?
def running? !!@running end
def start
def start return unless config.collect_metrics? @timer_task = Concurrent::TimerTask.execute( run_now: true, execution_interval: config.metrics_interval, timeout_interval: TIMEOUT_INTERVAL ) do begin collect_and_send true rescue StandardError => e error 'Error while collecting metrics: %e', e.inspect debug { e.backtrace.join("\n") } false end end @running = true end
def stop
def stop @timer_task.shutdown @running = false end