Class: Opstat::Parsers::Cpu
- Inherits:
-
Object
- Object
- Opstat::Parsers::Cpu
- Includes:
- Logging
- Defined in:
- lib/parsers/cpu.rb
Instance Method Summary collapse
Methods included from Logging
#log_level, #oplogger, #preconfig_logger
Instance Method Details
#parse_data(data:, time:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/parsers/cpu.rb', line 6 def parse_data(data:, time:) reports = [] cpu_summary_report = {} data.each do |line| case line when /(?<OPSTAT_TAG_cpu_id>cpu\S*)\s+(?<user>\d+)\s+(?<nice>\d+)\s+(?<system>\d+)\s+(?<idle>\d+)\s+(?<iowait>\d+)\s+(?<irq>\d+)\s+(?<softirq>\d+).*/ report = { :OPSTAT_TAG_cpu_id => $~[:OPSTAT_TAG_cpu_id], :user => $~[:user].to_i, :nice => $~[:nice].to_i, :system => $~[:system].to_i, :idle => $~[:idle].to_i, :iowait => $~[:iowait].to_i, :irq => $~[:irq].to_i, :softirq => $~[:softirq].to_i } if $~[:OPSTAT_TAG_cpu_id] == 'cpu' cpu_summary_report = report else reports << report end when /procs_blocked\s+(?<processes_blocked>\d+)/ cpu_summary_report[:processes_blocked] = $~[:processes_blocked].to_i when /procs_running\s+(?<processes_running>\d+)/ cpu_summary_report[:processes_running] = $~[:processes_running].to_i when /processes\s+(?<processes>\d+)/ cpu_summary_report[:processes] = $~[:processes].to_i when /ctxt\s+(?<context_switches>\d+)/ cpu_summary_report[:context_switches] = $~[:context_switches].to_i end end reports << cpu_summary_report return reports end |