Class: Mool::Cpu
Instance Attribute Summary collapse
-
#cores ⇒ Object
Returns the value of attribute cores.
-
#cpu_name ⇒ Object
Returns the value of attribute cpu_name.
-
#gnice ⇒ Object
Returns the value of attribute gnice.
-
#guest ⇒ Object
Returns the value of attribute guest.
-
#id ⇒ Object
Returns the value of attribute id.
-
#idle ⇒ Object
Returns the value of attribute idle.
-
#iowait ⇒ Object
Returns the value of attribute iowait.
-
#irq ⇒ Object
Returns the value of attribute irq.
-
#model_name ⇒ Object
Returns the value of attribute model_name.
-
#nice ⇒ Object
Returns the value of attribute nice.
-
#soft ⇒ Object
Returns the value of attribute soft.
-
#steal ⇒ Object
Returns the value of attribute steal.
-
#sys ⇒ Object
Returns the value of attribute sys.
-
#total ⇒ Object
Returns the value of attribute total.
-
#usr ⇒ Object
Returns the value of attribute usr.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(process_number, opt = {}) ⇒ Cpu
constructor
[“all”, “1”, “2”].
Methods inherited from Base
Constructor Details
#initialize(process_number, opt = {}) ⇒ Cpu
- “all”, “1”, “2”
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mool/cpu.rb', line 20 def initialize(process_number, opt={}) result = Mool::Cpu.processors unless result.include?(process_number.to_s) raise "Cpu name incorrect!. Posible values: #{result.join(', ')}" end result = opt.empty? ? Mool::Cpu.cpuinfo[process_number.to_s] : opt @cpu_name = "cpu_#{process_number}" @id = process_number @model_name = result['model_name'] @cores = result['cpu_cores'].to_i @usr = result['%usr'].to_f @nice = result['%nice'].to_f @sys = result['%sys'].to_f # This is kernel % @iowait = result['%iowait'].to_f @irq = result['%irq'].to_f @soft = result['%soft'].to_f @steal = result['%steal'].to_f @guest = result['%guest'].to_f @gnice = result['%gnice'].to_f @idle = result['%idle'].to_f @total = [@usr, @nice, @sys, @iowait, @irq, @soft, @steal, @guest].sum end |
Instance Attribute Details
#cores ⇒ Object
Returns the value of attribute cores.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def cores @cores end |
#cpu_name ⇒ Object
Returns the value of attribute cpu_name.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def cpu_name @cpu_name end |
#gnice ⇒ Object
Returns the value of attribute gnice.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def gnice @gnice end |
#guest ⇒ Object
Returns the value of attribute guest.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def guest @guest end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def id @id end |
#idle ⇒ Object
Returns the value of attribute idle.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def idle @idle end |
#iowait ⇒ Object
Returns the value of attribute iowait.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def iowait @iowait end |
#irq ⇒ Object
Returns the value of attribute irq.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def irq @irq end |
#model_name ⇒ Object
Returns the value of attribute model_name.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def model_name @model_name end |
#nice ⇒ Object
Returns the value of attribute nice.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def nice @nice end |
#soft ⇒ Object
Returns the value of attribute soft.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def soft @soft end |
#steal ⇒ Object
Returns the value of attribute steal.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def steal @steal end |
#sys ⇒ Object
Returns the value of attribute sys.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def sys @sys end |
#total ⇒ Object
Returns the value of attribute total.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def total @total end |
#usr ⇒ Object
Returns the value of attribute usr.
3 4 5 |
# File 'lib/mool/cpu.rb', line 3 def usr @usr end |
Class Method Details
.all ⇒ Object
82 83 84 |
# File 'lib/mool/cpu.rb', line 82 def self.all Mool::Cpu.cpuinfo.map { |key, value| Mool::Cpu.new(key, value) } end |
.cpuinfo ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/mool/cpu.rb', line 52 def self.cpuinfo cpu_info = {} mpstat = Mool::Command.mpstat.split("\n\n")[2].split("\n").map do |i| i.gsub(/^\S+:/, '').strip.split(/\s+/) end mpstat_vars = mpstat.shift mpstat_vars.shift mpstat.each do |data| res = {} core_name = data.shift data.each_with_index { |d, i| res.merge!(mpstat_vars[i] => d) } cpu_info.merge!(core_name => res) end Mool::Command.cpuinfo.gsub(/([^\n])\n([^\n])/, '\1 \2').scan(/processor\t*: (\d+).*model name\t*: (.*) stepping.*cpu cores\t*: (\d+)/).each do |v| cpu_info[v[0]]['model_name'] = v[1] cpu_info[v[0]]['cpu_cores'] = v[2] end cpu_info end |