bin/metrics-cpu.rb in sensu-plugins-cpu-checks-0.0.4 vs bin/metrics-cpu.rb in sensu-plugins-cpu-checks-1.0.0

- old
+ new

@@ -34,20 +34,25 @@ description: 'Metric naming scheme, text to prepend to metric', short: '-s SCHEME', long: '--scheme SCHEME', default: "#{Socket.gethostname}.cpu" + option :proc_path, + long: '--proc-path /proc', + proc: proc(&:to_f), + default: '/proc' + def run cpu_metrics = %w(user nice system idle iowait irq softirq steal guest) other_metrics = %w(ctxt processes procs_running procs_blocked btime intr) cpu_count = 0 - File.open('/proc/stat', 'r').each_line do |line| + File.open("#{config[:proc_path]}/stat", 'r').each_line do |line| info = line.split(/\s+/) next if info.empty? name = info.shift - if name.match(/cpu([0-9]+|)/) + if name =~ /cpu([0-9]+|)/ # #YELLOW cpu_count = cpu_count + 1 # rubocop:disable Style/SelfAssignment name = 'total' if name == 'cpu' info.size.times { |i| output "#{config[:scheme]}.#{name}.#{cpu_metrics[i]}", info[i] } end