Module: SensuPluginsCpuChecks::CommonInterrupts
- Defined in:
- lib/sensu-plugins-cpu-checks/common_interrupts.rb
Instance Method Summary collapse
Instance Method Details
#build_regexp(line) ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/sensu-plugins-cpu-checks/common_interrupts.rb', line 3 def build_regexp(line) regexp_string = '[[:space:]]*(?<irq_number>.+):' cpu_list = line.scan(/CPU\d+/) cpu_list.each do |name| regexp_string += "[[:space:]]*(?<#{name}>\\d+)" end regexp_string += '[[:space:]]*(?<irq_type>.*)' [Regexp.new(regexp_string), cpu_list] end |
#output_metrics(filename) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/sensu-plugins-cpu-checks/common_interrupts.rb', line 13 def output_metrics(filename) regexp = nil cpu_list = [] File.open("#{config[:proc_path]}/#{filename}", 'r').each_line.with_index do |line, index| if index.zero? regexp, cpu_list = build_regexp(line) else result = line.match(regexp) if result cpu_list.each do |name| key = [config[:scheme], name, result[:irq_type].split.join('-'), result[:irq_number]].reject(&:empty?) output key.join('.').to_s, result[name] end end end end end |