Class: OneApm::Collector::ProcPoller

Inherits:
ShellPoller show all
Defined in:
lib/one_apm/collector/support/proc_poller.rb

Constant Summary collapse

OA_UPTIME_PATH =
'/proc/uptime'.freeze

Instance Attribute Summary

Attributes inherited from ShellPoller

#pid

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShellPoller

kb_page_size, #memory

Class Method Details

.enable?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/one_apm/collector/support/proc_poller.rb', line 10

def self.enable?
  ::RUBY_PLATFORM.downcase =~ /linux/
end

Instance Method Details

#cpu_utilizationObject



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/one_apm/collector/support/proc_poller.rb', line 19

def cpu_utilization
  @pid = Process.pid
  stat = stats 
  total_time = stat[:utime].to_f + stat[:stime].to_f # in jiffies
  seconds = uptime - stat[:starttime].to_f / 100
  return 0.0 if seconds <= 0.0
  ((total_time * 1000.0 / 100.0) / seconds) / 10.0 / 100.0
rescue => e
  OneApm::Manager.logger.warn "Fetch cpu usage error: #{e.message}"
  0.0
end

#poll_memoryObject



14
15
16
17
# File 'lib/one_apm/collector/support/proc_poller.rb', line 14

def poll_memory
  return 0.0 unless File.exist?(proc_status_file)
  stats[:rss].to_f * OneApm::Collector::ShellPoller.kb_page_size / 1024.0
end

#to_sObject



31
32
33
# File 'lib/one_apm/collector/support/proc_poller.rb', line 31

def to_s
  "ProcPoller from: #{proc_status_file}"
end