Class: Aio::Module::Cmd::Maipu::ShowCpu

Inherits:
Aio::Module::Cmd::Maipu show all
Includes:
Aio::Module
Defined in:
lib/modules/cmd/maipu/show_cpu.rb

Instance Attribute Summary

Attributes inherited from Aio::Module::Cmd

#cmd_info, #context, #device_info, #ext_info, #useful, #warning_klass

Instance Method Summary collapse

Methods inherited from Aio::Module::Cmd

#author, #benchmark, #clear_useful, #cmd_full, #cmd_short, #description, #division, #key_stand, #license, #platform, #ranking, #set_defaults, #type

Methods included from Ui::Verbose

#clear_line, #print_error, #print_good, #progress_bar

Constructor Details

#initializeShowCpu

Returns a new instance of ShowCpu.



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/modules/cmd/maipu/show_cpu.rb', line 8

def initialize
  super({
    :cmd_full			=> "show cpu",
    :cmd_short		=> "sh cpu", 
    :author				=> "Elin",
    :description	=> "This is Maipu Command# show cpu",
    :ranking			=> Ranking_1,
    :platform			=> "all",
    :benchmark		=> {
      :used_percent		=> ["<", 70.0],		
    }
  })
end

Instance Method Details

#parseObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/modules/cmd/maipu/show_cpu.rb', line 22

def parse
  cont = self.context.dup
  useful[:cpu] = {}

  idle = 0
  cont.readline_match_block(/IDLE (?<cpu_idle>\d+)%/) do |block|
    idle = block[:cpu_idle].to_i
  end

  cont.readline_match_block(/TOTAL (?<cpu_total>\d+)%/) do |block|
    used = block[:cpu_total].to_i - idle
    block.warning_serious(useful[:cpu], :used_percent, self, string: used.to_s)
  end
end