Class: Cloudscopes::System
- Inherits:
-
Object
- Object
- Cloudscopes::System
- Defined in:
- lib/cloudscopes/system.rb
Instance Method Summary collapse
- #bluepill_ok?(name) ⇒ Boolean
- #cpucount ⇒ Object
-
#iostat ⇒ Object
Read www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats for the field meanings this method returns fields 4~14 as sum for all devices (as array indexes 0..10).
- #loadavg5 ⇒ Object
- #service(name) ⇒ Object
Instance Method Details
#bluepill_ok?(name) ⇒ Boolean
29 30 31 32 |
# File 'lib/cloudscopes/system.rb', line 29 def bluepill_ok?(name) %x(/usr/local/bin/bluepill wfs status | grep -v up | grep pid) $?.exitstatus == 1 # grep pid should not match because all the pids are "up" end |
#cpucount ⇒ Object
9 10 11 |
# File 'lib/cloudscopes/system.rb', line 9 def cpucount File.read("/proc/cpuinfo").split("\n").grep(/^processor\s+/).count end |
#iostat ⇒ Object
Read www.kernel.org/doc/Documentation/ABI/testing/procfs-diskstats for the field meanings this method returns fields 4~14 as sum for all devices (as array indexes 0..10)
15 16 17 18 19 20 21 22 |
# File 'lib/cloudscopes/system.rb', line 15 def iostat File.read("/proc/diskstats").split("\n").collect do |dev| dev.gsub(/^\s+/,"").split(/\s+/)[3..13].collect(&:to_i) end.inject() do |sums,vals| sums ||= vals.collect { 0 } # init with zeros sums.zip(vals).map {|a| a.reduce(:+) } # sum array values end end |
#loadavg5 ⇒ Object
5 6 7 |
# File 'lib/cloudscopes/system.rb', line 5 def loadavg5 File.read("/proc/loadavg").split(/\s+/).first.to_f end |
#service(name) ⇒ Object
24 25 26 27 |
# File 'lib/cloudscopes/system.rb', line 24 def service(name) %x(PATH=/usr/sbin:/usr/bin:/sbin:/bin /usr/sbin/service #{name} status 2>/dev/null) $?.exitstatus == 0 end |