Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a new cpu_count metric with number of CPUs #560

Merged
merged 1 commit into from
Apr 27, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions plugins/system/cpu-metrics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ 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+/)
next if info.empty?
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
Expand All @@ -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
Expand Down