diff options
author | tpowell-progress <104777878+tpowell-progress@users.noreply.github.com> | 2022-08-30 15:38:30 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 15:38:30 -0400 |
commit | 5fabbdf426f1b767040b3051727e057353f2034d (patch) | |
tree | 45dabb2d40d3dc0aa33f69bc6f981f550fb8ff2a | |
parent | 155b5502623fcab7d686b0f13e343eb60446d2de (diff) | |
parent | a449813c7dc7c75738a7937f252883bb20289268 (diff) | |
download | ohai-5fabbdf426f1b767040b3051727e057353f2034d.tar.gz |
Merge pull request #1761 from stanhu/sh-cpuinfo-fallback
Fall back to /proc/cpuinfo if lscpu doesn't have CPU totals
-rw-r--r-- | lib/ohai/plugins/cpu.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/ohai/plugins/cpu.rb b/lib/ohai/plugins/cpu.rb index e26a7ace..1d37c39f 100644 --- a/lib/ohai/plugins/cpu.rb +++ b/lib/ohai/plugins/cpu.rb @@ -344,15 +344,23 @@ Ohai.plugin(:CPU) do cpuinfo end + # Check if the `lscpu` data looks reasonable + def valid_lscpu?(lscpu) + return false if lscpu.empty? + return false if %i{total real cores}.any? { |key| lscpu[key].to_i == 0 } + + true + end + collect_data(:linux) do cpuinfo = parse_cpuinfo lscpu = parse_lscpu(cpuinfo) - # If we don't have any data from lscpu then get it from /proc/cpuinfo - if lscpu.empty? - cpu cpuinfo - else + # If we don't have any sensible data from lscpu then get it from /proc/cpuinfo + if valid_lscpu?(lscpu) cpu lscpu + else + cpu cpuinfo end end |