Class: Cloudscopes::System

Inherits:
Object
  • Object
show all
Defined in:
lib/cloudscopes/system.rb

Instance Method Summary collapse

Instance Method Details

#bluepill_ok?(name) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
# File 'lib/cloudscopes/system.rb', line 40

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

#cpucountObject



20
21
22
# File 'lib/cloudscopes/system.rb', line 20

def cpucount
  File.read("/proc/cpuinfo").split("\n").grep(/^processor\s+/).count
end

#iostatObject

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)



26
27
28
29
30
31
32
33
# File 'lib/cloudscopes/system.rb', line 26

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

#loadavg5Object



16
17
18
# File 'lib/cloudscopes/system.rb', line 16

def loadavg5
  File.read("/proc/loadavg").split(/\s+/).first.to_f
end

#service(name) ⇒ Object



35
36
37
38
# File 'lib/cloudscopes/system.rb', line 35

def service(name)
  %x(PATH=/usr/sbin:/usr/bin:/sbin:/bin /usr/sbin/service #{name} status 2>/dev/null)
  $?.exitstatus == 0
end