Sha256: ba84ac269bba9f1d1cb7bdda8acc5ec711cfa4c9a4a6c698be96b9e7cfd67b88

Contents?: true

Size: 1.59 KB

Versions: 11

Compression:

Stored size: 1.59 KB

Contents

module AgentHelpers
  # Indicates whether we are running in a pid namespace (such as
  # Docker).
  #
  def pid_namespace?
    return false unless @is_linux
    Process.pid != get_real_pid
  end

  # Attempts to determine the true process ID by querying the
  # /proc/<pid>/sched file.  This works on linux currently.
  #
  def get_real_pid
    raise RuntimeError.new("Unsupported platform: get_real_pid") unless @is_linux

    sched_file = "/proc/#{Process.pid}/sched"
    pid = Process.pid

    if File.exist?(sched_file)
      v = File.open(sched_file, &:readline)
      pid = v.match(/\d+/).to_s.to_i
    end
    pid
  end

  # Returns the PID that we are reporting to
  #
  def report_pid
    @process[:report_pid]
  end

  # Determine whether the pid has changed since Agent start.
  #
  # @ return [Boolean] true or false to indicate if forked
  #
  def forked?
    @process[:pid] != Process.pid
  end

  # Indicates if the agent is ready to send metrics
  # and/or data.
  #
  def ready?
    # In test, we're always ready :-)
    return true if ENV.key?('INSTANA_TEST')

    # Occasionally Run Fork detection
    if rand(10) > 8
      if !@is_resque_worker && (@process[:pid] != Process.pid)
        ::Instana.logger.debug "Instana: detected fork. (this pid: #{Process.pid}/#{Process.ppid})  Calling after_fork"
        after_fork
      end
    end

    @state == :ready || @state == :announced
  rescue => e
    Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
    Instana.logger.debug { e.backtrace.join("\r\n") } unless ENV.key?('INSTANA_TEST')
    return false
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
instana-1.10.10 lib/instana/agent/helpers.rb
instana-1.10.10-java lib/instana/agent/helpers.rb
instana-1.10.9-java lib/instana/agent/helpers.rb
instana-1.10.9 lib/instana/agent/helpers.rb
instana-1.10.8-java lib/instana/agent/helpers.rb
instana-1.10.8 lib/instana/agent/helpers.rb
instana-1.10.7 lib/instana/agent/helpers.rb
instana-1.10.7-java lib/instana/agent/helpers.rb
instana-1.10.6-java lib/instana/agent/helpers.rb
instana-1.10.6 lib/instana/agent/helpers.rb
instana-1.10.6.fastrabbit lib/instana/agent/helpers.rb