Class: Sysresources::SysResource
- Inherits:
-
Object
- Object
- Sysresources::SysResource
- Defined in:
- lib/sysresources.rb
Instance Method Summary collapse
-
#cores ⇒ Object
get cpu cores #.
-
#get_cpu ⇒ Object
get cpu percent #.
-
#get_disk ⇒ Object
get disk stats #.
-
#get_load ⇒ Object
get cpu load #.
-
#get_proc ⇒ Object
get running processes #.
-
#get_ram ⇒ Object
get memory stats #.
-
#get_stat ⇒ Object
get stats #.
-
#get_upt ⇒ Object
get uptime #.
-
#header ⇒ Object
get header #.
-
#name(name) ⇒ Object
color name #.
-
#run_stats ⇒ Object
print stats #.
-
#stat(stat) ⇒ Object
color stat #.
Instance Method Details
#cores ⇒ Object
get cpu cores #
58 59 60 61 62 |
# File 'lib/sysresources.rb', line 58 def cores raw = Sys::CPU.processors cnt = raw[0]['cpu_cores'] return cnt.to_i end |
#get_cpu ⇒ Object
get cpu percent #
74 75 76 77 78 79 80 81 |
# File 'lib/sysresources.rb', line 74 def get_cpu cmd = %x(ps -eo "%C").split("\n") sum = cmd.map(&:to_f).reduce(0,:+) cpu = (sum/cores).round(2) stat(cpu) + "%" rescue $error end |
#get_disk ⇒ Object
get disk stats #
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sysresources.rb', line 36 def get_disk multi = 1024 dirc = File.exist?($root) ? $root : "/" root = $disk.stat(dirc) size = root.block_size avil = root.blocks_available gb = size * avil /multi/multi/multi stat("#{gb}G") rescue $error end |
#get_load ⇒ Object
get cpu load #
65 66 67 68 69 70 71 |
# File 'lib/sysresources.rb', line 65 def get_load info = Sys::CPU.load_avg load = info.join(", ") stat(load) rescue $error end |
#get_proc ⇒ Object
get running processes #
94 95 96 97 98 99 |
# File 'lib/sysresources.rb', line 94 def get_proc proc = %x(ps -A --no-headers | wc -l) stat(proc) rescue $error end |
#get_ram ⇒ Object
get memory stats #
49 50 51 52 53 54 55 |
# File 'lib/sysresources.rb', line 49 def get_ram cmd = %x(free -h) free = cmd.split(" ")[9] stat(free) rescue $error end |
#get_stat ⇒ Object
get stats #
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/sysresources.rb', line 110 def get_stat fromsys = { "disk:" => get_disk, "ram:" => get_ram, "cpu:" => get_cpu, "uptime:" => get_upt, "process:" => get_proc } fromsys.each do |k,v| puts " xxxxxxxxx #{name(k)}"+"#{v}" end end |
#get_upt ⇒ Object
get uptime #
84 85 86 87 88 89 90 91 |
# File 'lib/sysresources.rb', line 84 def get_upt cmd = %x(uptime) upt = cmd.split(",")[0] upt = upt.split("up")[1] stat(upt.strip()) rescue $error end |
#header ⇒ Object
get header #
102 103 104 105 106 107 |
# File 'lib/sysresources.rb', line 102 def header host = %x(hostname).strip() end_ = "\n\n" for_ = "[ #{host} #{$header} ]" puts "\n"+for_+end_ end |
#name(name) ⇒ Object
color name #
30 31 32 33 |
# File 'lib/sysresources.rb', line 30 def name(name) name = name.to_s name.white end |
#run_stats ⇒ Object
print stats #
124 125 126 127 128 |
# File 'lib/sysresources.rb', line 124 def run_stats header get_stat exit(0) end |
#stat(stat) ⇒ Object
color stat #
24 25 26 27 |
# File 'lib/sysresources.rb', line 24 def stat(stat) stat = stat.to_s stat.yellow end |