class ElasticAPM::Metrics::Registry

def start

def start
  unless config.collect_metrics?
    debug 'Skipping metrics'
    return
  end
  debug 'Starting metrics'
  # Only set the @sets once, in case we stop
  # and start again.
  if @sets.nil?
    sets = {
      system: CpuMemSet,
      vm: VMSet,
      breakdown: BreakdownSet,
      transaction: TransactionSet
    }
    if defined?(JVMSet)
      debug "Enabling JVM metrics collection"
      sets[:jvm] = JVMSet
    end
    @sets = sets.each_with_object({}) do |(key, kls), _sets_|
      debug "Adding metrics collector '#{kls}'"
      _sets_[key] = kls.new(config)
    end
  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