Class: Jah::Cpu

Inherits:
Object
  • Object
show all
Includes:
Command
Defined in:
lib/jah/commands/cpu.rb

Constant Summary

Constants included from Command

Jah::Command::COMM

Class Method Summary collapse

Methods included from Command

find, included

Class Method Details

.coresObject



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_loadObject



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

.loadObject



8
9
10
11
# File 'lib/jah/commands/cpu.rb', line 8

def load
  read
  "Med: #{@res[:med]}"
end

.readObject



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