def setup
      # The announce timer
      # We attempt to announce this ruby sensor to the host agent.
      # In case of failure, we try again in 30 seconds.
      @announce_timer = @timers.every(30) do
        if @state == :unannounced
          if host_agent_available? && announce_sensor
            transition_to(:announced)
            ::Instana.logger.info "Host agent available. We're in business. (#{@state} pid:#{Process.pid} #{@process[:name]})"
          end
        end
      end

      # The collect timer
      # If we are in announced state, send metric data (only delta reporting)
      # every ::Instana.config[:collector][:interval] seconds.
      @collect_timer = @timers.every(::Instana.config[:collector][:interval]) do
        # Make sure that this block doesn't get called more often than the interval.  This can
        # happen on high CPU load and a back up of timer runs.  If we are called before `interval`
        # then we just skip.
        unless (Time.now - @last_collect_run) < ::Instana.config[:collector][:interval]
          @last_collect_run = Time.now
          if @state == :announced
            if !::Instana.collector.collect_and_report
              # If report has been failing for more than 1 minute,
              # fall back to unannounced state
              if (Time.now - @entity_last_seen) > 60
                ::Instana.logger.warn "Host agent offline for >1 min.  Going to sit in a corner..."
                transition_to(:unannounced)
              end
            end
            ::Instana.processor.send
          end
        end
      end
    end
def setup
      # The announce timer
      # We attempt to announce this ruby sensor to the host agent.
      # In case of failure, we try again in 30 seconds.
      @announce_timer = @timers.every(30) do
        if @state == :unannounced
          if host_agent_available? && announce_sensor
            transition_to(:announced)
            ::Instana.logger.info "Host agent available. We're in business. (#{@state} pid:#{Process.pid} #{@process[:name]})"
          end
        end
      end

      # The collect timer
      # If we are in announced state, send metric data (only delta reporting)
      # every ::Instana.config[:collector][:interval] seconds.
      @collect_timer = @timers.every(::Instana.config[:collector][:interval]) do
        # Make sure that this block doesn't get called more often than the interval.  This can
        # happen on high CPU load and a back up of timer runs.  If we are called before `interval`
        # then we just skip.
        unless (Time.now - @last_collect_run) < ::Instana.config[:collector][:interval]
          @last_collect_run = Time.now
          if @state == :announced
            if !::Instana.collector.collect_and_report
              # If report has been failing for more than 1 minute,
              # fall back to unannounced state
              if (Time.now - @entity_last_seen) > 60
                ::Instana.logger.warn "Host agent offline for >1 min.  Going to sit in a corner..."
                transition_to(:unannounced)
              end
            end
            ::Instana.processor.send
          end
        end
      end
    end
Sets up periodic timers and starts the agent in a background thread.