Module: Mool::Command

Defined in:
lib/mool/command.rb

Class Method Summary collapse

Class Method Details

.all_partitionsObject



47
48
49
# File 'lib/mool/command.rb', line 47

def self.all_partitions
  File.read('/proc/partitions')
end

.cpuinfoObject

CPU COMMANDS



5
6
7
# File 'lib/mool/command.rb', line 5

def self.cpuinfo
  File.read('/proc/cpuinfo')
end

.dfObject



35
36
37
# File 'lib/mool/command.rb', line 35

def self.df
  `POSIXLY_CORRECT=512 df`
end

.file_systemObject



22
23
24
# File 'lib/mool/command.rb', line 22

def self.file_system
  Dir.glob('/sys/fs/**/*')
end

.holders(path) ⇒ Object



43
44
45
# File 'lib/mool/command.rb', line 43

def self.holders(path)
  Dir.glob("#{path}/holders/*").uniq
end

.loadavgObject



80
81
82
# File 'lib/mool/command.rb', line 80

def self.loadavg
  File.read('/proc/loadavg').chomp
end

.logical_name(path) ⇒ Object

DISK COMMANDS



14
15
16
# File 'lib/mool/command.rb', line 14

def self.logical_name(path)
  File.read("#{path}/dm/name") rescue nil
end

.meminfoObject

MEMORY COMMANDS



61
62
63
# File 'lib/mool/command.rb', line 61

def self.meminfo
  File.read('/proc/meminfo')
end

.mountObject



18
19
20
# File 'lib/mool/command.rb', line 18

def self.mount
  File.read('/proc/mounts')
end

.mpstatObject



9
10
11
# File 'lib/mool/command.rb', line 9

def self.mpstat
  File.read('|mpstat -P ALL 1 1')
end

.partitions(devname) ⇒ Object



39
40
41
# File 'lib/mool/command.rb', line 39

def self.partitions(devname)
  Dir.glob("/sys/block/#{devname}/#{devname}*")
end

.psObject

PROCESS COMMANDS



66
67
68
69
# File 'lib/mool/command.rb', line 66

def self.ps
  # `ps --no-headers -o pid,user,pcpu,pmem,rss,priority,time,stat,nice,args -A`
  `ps --no-headers -o ruser,user,rgroup,group,pid,ppid,pgid,pcpu,vsz,nice,etime,time,tty,comm,args=HEADER -A`
end

.root_block_device?(devname) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/mool/command.rb', line 51

def self.root_block_device?(devname)
  File.exist?("/sys/block/#{devname}") &&
    !Dir.glob("/sys/block/#{devname}/slaves/*").present?
end

.swap(lname = nil) ⇒ Object



30
31
32
33
# File 'lib/mool/command.rb', line 30

def self.swap(lname = nil)
  result = File.read('/proc/swaps')
  lname.present? ? result[/#{lname} /] : result
end

.topObject



71
72
73
# File 'lib/mool/command.rb', line 71

def self.top
  `top -c -b -n1`
end

.uevent(path) ⇒ Object



26
27
28
# File 'lib/mool/command.rb', line 26

def self.uevent(path)
  File.read("#{path}/uevent")
end

.unameObject

SYSTEM COMMANDS



76
77
78
# File 'lib/mool/command.rb', line 76

def self.uname
  `uname -r`.chomp
end

.uptimeObject



84
85
86
# File 'lib/mool/command.rb', line 84

def self.uptime
  `cat /proc/uptime`.chomp
end