Skip to content

Commit

Permalink
Fixes #97 - Use nproc command to count cores
Browse files Browse the repository at this point in the history
The nproc command should be available on most Linux distros and
can replace the `cores` method in riemann-health.

This should address issues where a host has multiple cores with the
same ID.
  • Loading branch information
jamtur01 committed Dec 4, 2016
1 parent 7549da6 commit 41a89a8
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions bin/riemann-health
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Riemann::Tools::Health
@load = method :freebsd_load
@memory = method :freebsd_memory
else
@cores = cores
@cores = `nproc`.to_i
puts "WARNING: OS '#{@ostype}' not explicitly supported. Falling back to Linux" unless @ostype == "linux"
@cpu = method :linux_cpu
@disk = method :disk
Expand Down Expand Up @@ -70,23 +70,6 @@ class Riemann::Tools::Health
)
end

def cores
i = 0;
File.read("/proc/cpuinfo").split(/\n\n/).inject({}) do |cores, p|
physical_id = p[/physical id\s+:\s+(\d+)/, 1]
core_id = p[/core id\s+:\s+(\d+)/, 1]
if physical_id and core_id
cores["#{physical_id}:#{core_id}"] = true
elsif physical_id
cores["#{physical_id}:"] = true
else
cores[i += 1] = true;
end

cores
end.size
end

def report_pct(service, fraction, report)
if fraction
if fraction > @limits[service][:critical]
Expand Down

0 comments on commit 41a89a8

Please sign in to comment.