class God::System::SlashProcPoller
Constants
- MeminfoPath
- RequiredPaths
- UptimePath
Public Class Methods
new(pid)
click to toggle source
Calls superclass method
God::System::PortablePoller.new
# File lib/god/system/slash_proc_poller.rb, line 22 def initialize(pid) super(pid) unless @@total_mem # in K File.open(MeminfoPath) do |f| @@total_mem = f.gets.split[1] end end end
usable?()
click to toggle source
FreeBSD has /proc by default, but nothing mounted there! So we should check
for the actual required paths! Returns true if RequiredPaths
are readable.
# File lib/god/system/slash_proc_poller.rb, line 16 def self.usable? RequiredPaths.all? do |path| test(?r, path) && readable?(path) end end
Private Class Methods
readable?(path)
click to toggle source
Some systems (CentOS?) have a /proc, but they can hang when trying to read from them. Try to use this sparingly as it is expensive.
# File lib/god/system/slash_proc_poller.rb, line 62 def self.readable?(path) begin timeout(1) { File.read(path) } rescue Timeout::Error false end end
Public Instance Methods
memory()
click to toggle source
# File lib/god/system/slash_proc_poller.rb, line 32 def memory stat[:rss].to_i * @@kb_per_page rescue # This shouldn't fail is there's an error (or proc doesn't exist) 0 end
percent_cpu()
click to toggle source
TODO: Change this to calculate the wma instead
# File lib/god/system/slash_proc_poller.rb, line 45 def percent_cpu stats = stat total_time = stats[:utime].to_i + stats[:stime].to_i # in jiffies seconds = uptime - stats[:starttime].to_i / @@hertz if seconds == 0 0 else ((total_time * 1000 / @@hertz) / seconds) / 10 end rescue # This shouldn't fail is there's an error (or proc doesn't exist) 0 end
percent_memory()
click to toggle source
# File lib/god/system/slash_proc_poller.rb, line 38 def percent_memory (memory / @@total_mem.to_f) * 100 rescue # This shouldn't fail is there's an error (or proc doesn't exist) 0 end
Private Instance Methods
stat()
click to toggle source
# File lib/god/system/slash_proc_poller.rb, line 75 def stat stats = {} stats[:pid], stats[:comm], stats[:state], stats[:ppid], stats[:pgrp], stats[:session], stats[:tty_nr], stats[:tpgid], stats[:flags], stats[:minflt], stats[:cminflt], stats[:majflt], stats[:cmajflt], stats[:utime], stats[:stime], stats[:cutime], stats[:cstime], stats[:priority], stats[:nice], _, stats[:itrealvalue], stats[:starttime], stats[:vsize], stats[:rss], stats[:rlim], stats[:startcode], stats[:endcode], stats[:startstack], stats[:kstkesp], stats[:kstkeip], stats[:signal], stats[:blocked], stats[:sigignore], stats[:sigcatch], stats[:wchan], stats[:nswap], stats[:cnswap], stats[:exit_signal], stats[:processor], stats[:rt_priority], stats[:policy] = File.read("/proc/#{@pid}/stat").scan(/\(.*?\)|\w+/) stats end
uptime()
click to toggle source
in seconds
# File lib/god/system/slash_proc_poller.rb, line 71 def uptime File.read(UptimePath).split[0].to_f end