Permalink
Browse files

* Fixed support for operating systems with /proc, but no procfs (e.g…

…. FreeBSD 7)
  • Loading branch information...
1 parent 74730d4 commit b6f9cad5479c102da63fe0c614751851d6540027 @raggi raggi committed Jun 16, 2008
Showing with 17 additions and 3 deletions.
  1. +1 −1 lib/god/system/process.rb
  2. +16 −2 lib/god/system/slash_proc_poller.rb
View
2 lib/god/system/process.rb
@@ -30,7 +30,7 @@ def percent_cpu
private
def fetch_system_poller
- if test(?d, '/proc')
+ if SlashProcPoller.usable?
SlashProcPoller
else
PortablePoller
View
18 lib/god/system/slash_proc_poller.rb
@@ -5,11 +5,25 @@ class SlashProcPoller < PortablePoller
@@hertz = 100
@@total_mem = nil
+ MeminfoPath = '/proc/meminfo'
+ UptimePath = '/proc/uptime'
+
+ RequiredPaths = [MeminfoPath, UptimePath]
+
+ # FreeBSD has /proc by default, but nothing mounted there!
+ # So we should check for the actual required paths!
+ # Returns true if +RequiredPaths+ are readable.
+ def self.usable?
+ RequiredPaths.all? do |path|
+ test(?r, path)
+ end
+ end
+
def initialize(pid)
super(pid)
unless @@total_mem # in K
- File.open("/proc/meminfo") do |f|
+ File.open(MeminfoPath) do |f|
@@total_mem = f.gets.split[1]
end
end
@@ -39,7 +53,7 @@ def percent_cpu
# in seconds
def uptime
- File.read('/proc/uptime').split[0].to_f
+ File.read(UptimePath).split[0].to_f
end
def stat

0 comments on commit b6f9cad

Please sign in to comment.