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 #
51 52 53 54 55 |
# File 'lib/sysresources.rb', line 51 def cores raw = Sys::CPU.processors cnt = raw[0]['cpu_cores'] return cnt.to_i end |
#get_cpu ⇒ Object
get cpu percent #
65 66 67 68 69 70 |
# File 'lib/sysresources.rb', line 65 def get_cpu cmd = %x(ps -eo "%C").split("\n") sum = cmd.map(&:to_f).reduce(0,:+) cpu = (sum/cores).round(2) return stat(cpu) + "%" end |
#get_disk ⇒ Object
get disk stats #
34 35 36 37 38 39 40 41 |
# File 'lib/sysresources.rb', line 34 def get_disk multi = 1024 root = $disk.stat("/home") size = root.block_size avil = root.blocks_available gb = size * avil /multi/multi/multi return stat("#{gb}G") end |
#get_load ⇒ Object
get cpu load #
58 59 60 61 62 |
# File 'lib/sysresources.rb', line 58 def get_load info = Sys::CPU.load_avg load = info.join(", ") return stat(load) end |
#get_proc ⇒ Object
get running processes #
81 82 83 84 |
# File 'lib/sysresources.rb', line 81 def get_proc proc = %x(ps -A --no-headers | wc -l) return stat(proc) end |
#get_ram ⇒ Object
get memory stats #
44 45 46 47 48 |
# File 'lib/sysresources.rb', line 44 def get_ram cmd = %x(free -h) free = cmd.split(" ")[9] return stat(free) end |
#get_stat ⇒ Object
get stats #
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/sysresources.rb', line 95 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 #
73 74 75 76 77 78 |
# File 'lib/sysresources.rb', line 73 def get_upt cmd = %x(uptime) upt = cmd.split(",")[0] upt = upt.split("up")[1] return stat(upt.strip()) end |
#header ⇒ Object
get header #
87 88 89 90 91 92 |
# File 'lib/sysresources.rb', line 87 def header host = %x(hostname).strip() end_ = "\n\n" for_ = "[ #{host} #{$header} ]" puts "\n"+for_+end_ end |
#name(name) ⇒ Object
color name #
28 29 30 31 |
# File 'lib/sysresources.rb', line 28 def name(name) name = name.to_s return name.white end |
#run_stats ⇒ Object
print stats #
109 110 111 112 |
# File 'lib/sysresources.rb', line 109 def run_stats header get_stat end |
#stat(stat) ⇒ Object
color stat #
22 23 24 25 |
# File 'lib/sysresources.rb', line 22 def stat(stat) stat = stat.to_s return stat.yellow end |