class ElasticAPM::Metrics::Registry
@api private
def collect
def collect sets.each_value.each_with_object([]) do |set, arr| samples = set.collect next unless samples arr.concat(samples) end end
def collect_and_send
def collect_and_send metricsets = collect metricsets.compact! metricsets.each do |m| callback.call(m) end end
def get(key)
def get(key) sets.fetch(key) end
def initialize(config, &block)
def initialize(config, &block) @config = config @callback = block end
def running?
def running? !!@running end
def start
def start unless config.collect_metrics? debug 'Skipping metrics' return end debug 'Starting metrics' @sets = { system: CpuMemSet, vm: VMSet, breakdown: BreakdownSet, transaction: TransactionSet }.each_with_object({}) do |(key, kls), sets| debug "Adding metrics collector '#{kls}'" sets[key] = kls.new(config) end @timer_task = Concurrent::TimerTask.execute( run_now: true, execution_interval: config.metrics_interval, timeout_interval: TIMEOUT_INTERVAL ) do begin debug 'Collecting metrics' 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 return unless running? debug 'Stopping metrics' @timer_task.shutdown @running = false end