Module: AgentHelpers
- Included in:
- Instana::Agent
- Defined in:
- lib/instana/agent/helpers.rb
Instance Method Summary collapse
-
#forked? ⇒ Boolean
Determine whether the pid has changed since Agent start.
-
#get_real_pid ⇒ Object
Attempts to determine the true process ID by querying the /proc/<pid>/sched file.
-
#pid_namespace? ⇒ Boolean
Indicates whether we are running in a pid namespace (such as Docker).
-
#ready? ⇒ Boolean
Indicates if the agent is ready to send metrics and/or data.
-
#report_pid ⇒ Object
Returns the PID that we are reporting to.
Instance Method Details
#forked? ⇒ Boolean
Determine whether the pid has changed since Agent start.
@ return [Boolean] true or false to indicate if forked
36 37 38 |
# File 'lib/instana/agent/helpers.rb', line 36 def forked? @process[:pid] != Process.pid end |
#get_real_pid ⇒ Object
Attempts to determine the true process ID by querying the /proc/<pid>/sched file. This works on linux currently.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/instana/agent/helpers.rb', line 13 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 |
#pid_namespace? ⇒ Boolean
Indicates whether we are running in a pid namespace (such as Docker).
5 6 7 8 |
# File 'lib/instana/agent/helpers.rb', line 5 def pid_namespace? return false unless @is_linux Process.pid != get_real_pid end |
#ready? ⇒ Boolean
Indicates if the agent is ready to send metrics and/or data.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/instana/agent/helpers.rb', line 43 def ready? # In test, we're always ready :-) return true if ENV['INSTANA_GEM_TEST'] if !@is_resque_worker && forked? ::Instana.logger.debug "Instana: detected fork. (this pid: #{Process.pid}/#{Process.ppid}) Calling after_fork" after_fork end @state == :announced rescue => e Instana.logger.debug "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.}" Instana.logger.debug e.backtrace.join("\r\n") unless ::Instana.test? return false end |
#report_pid ⇒ Object
Returns the PID that we are reporting to
28 29 30 |
# File 'lib/instana/agent/helpers.rb', line 28 def report_pid @process[:report_pid] end |