From a465258339592e17c11846fa0ba46cd4f567137c Mon Sep 17 00:00:00 2001 From: Jaime Gago Date: Wed, 23 Apr 2014 17:46:42 -0700 Subject: [PATCH] Add a new cpu_count metric with number of CPUs --- plugins/system/cpu-metrics.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/system/cpu-metrics.rb b/plugins/system/cpu-metrics.rb index 90cbfbf2a..a2936b62c 100755 --- a/plugins/system/cpu-metrics.rb +++ b/plugins/system/cpu-metrics.rb @@ -15,6 +15,7 @@ class CpuGraphite < Sensu::Plugin::Metric::CLI::Graphite def run cpu_metrics = ['user', 'nice', 'system', 'idle', 'iowait', 'irq', 'softirq', 'steal', 'guest'] other_metrics = ['ctxt', 'processes', 'procs_running', 'procs_blocked', 'btime', 'intr'] + cpu_count = 0 File.open("/proc/stat", "r").each_line do |line| info = line.split(/\s+/) @@ -22,6 +23,7 @@ def run name = info.shift if name.match(/cpu([0-9]+|)/) + cpu_count = cpu_count + 1 name = 'total' if name == 'cpu' cpu_metrics.size.times { |i| output "#{config[:scheme]}.#{name}.#{cpu_metrics[i]}", info[i] } end @@ -30,6 +32,11 @@ def run output "#{config[:scheme]}.#{name}", info.last end end + if cpu_count > 0 + # writes the number of cpus, the minus 1 is because /proc/stat/ + # first line is a "cpu" which is stats for total cpus + output "#{config[:scheme]}.cpu_count", cpu_count - 1 + end ok end