Class: Jah::Cpu
Constant Summary
Constants included from Command
Class Method Summary collapse
Methods included from Command
Class Method Details
.cores ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/jah/commands/cpu.rb', line 28 def cores @cores ||= case RUBY_PLATFORM when /linux/ then `cat /proc/cpuinfo | grep 'model name' | wc -l`.to_i when /darwin/ then `hwprefs cpu_count`.to_i else 1 end end |
.cpu_load ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/jah/commands/cpu.rb', line 20 def cpu_load if `uptime` =~ /load average(s*): ([\d.]+)(,*) ([\d.]+)(,*) ([\d.]+)\Z/ { :one => $2.to_f, :five => $4.to_f, :ten => $6.to_f } end end |
.load ⇒ Object
8 9 10 11 |
# File 'lib/jah/commands/cpu.rb', line 8 def load read "Med: #{@res[:med]}" end |
.read ⇒ Object
13 14 15 16 17 18 |
# File 'lib/jah/commands/cpu.rb', line 13 def read @res = cpu_load @res[:load] = @res.values.join(", ") @res[:med] = @res[:ten] / @res[:cores] = cores @res end |