Class: Aio::Module::Cmd::H3C::DisplayCpu
- Inherits:
-
Aio::Module::Cmd::H3C
- Object
- Aio::Module::Cmd
- Aio::Module::Cmd::H3C
- Aio::Module::Cmd::H3C::DisplayCpu
- Includes:
- Aio::Module
- Defined in:
- lib/modules/cmd/h3c/display_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
-
#initialize ⇒ DisplayCpu
constructor
A new instance of DisplayCpu.
- #parse ⇒ Object
- #parse_cpu(context) ⇒ Object
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
#initialize ⇒ DisplayCpu
Returns a new instance of DisplayCpu.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/modules/cmd/h3c/display_cpu.rb', line 8 def initialize super({ :cmd_full => "display cpu-usage", :cmd_short => "dis cpu", :author => "Elin", :description => "This is H3C Command# display cpu-usage", :ranking => Ranking_1, :platform => "all", :benchmark => { :seconds_5 => ["<", 50], :minute_1 => ["<", 50], :minutes_5 => ["<", 50], }, }) end |
Instance Method Details
#parse ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/modules/cmd/h3c/display_cpu.rb', line 24 def parse cont = self.context.dup useful[:cpu] = {} loop do cont.readline_range(/(Slot|Unit) \d?\s?(CPU \d+\s+)?CPU usage/, reg_blank) do |cont_layer| parse_cpu(cont_layer) end end useful[:cpu] end |
#parse_cpu(context) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/modules/cmd/h3c/display_cpu.rb', line 35 def parse_cpu(context) cpu = {} useful[:cpu] = cpu context.readline_match_block(/(Slot|Unit) (?<slot_id>\d?)\s?(CPU \d+\s+)?CPU/) do |block| # 目前只保留 slot 0 的CPU使用率 #return if block[:slot_id].to_s != '0' # 有可能没有 slot 项 if block[:slot_id].empty? block.update(cpu, :slot_id, '0') else block.update(cpu, :slot_id) end end context.readline_match_block(/(?<seconds_5>\d+)% in last 5 seconds/) do |block| block.warning_serious(cpu, :seconds_5, self) end context.readline_match_block(/(?<minute_1>\d+)% in last 1 minute/) do |block| block.warning_serious(cpu, :minute_1, self) end context.readline_match_block(/(?<minutes_5>\d+)% in last 5 minutes/) do |block| block.warning_serious(cpu, :minutes_5, self) end end |