diff options
author | curiositycasualty <isa@getchef.com> | 2015-03-13 11:29:14 -0400 |
---|---|---|
committer | curiositycasualty <isa@getchef.com> | 2015-03-13 11:29:14 -0400 |
commit | 9abb4468006c51c9b6971e58d220f827be7d7051 (patch) | |
tree | eb27f61c913d9ac9860fd4a98a9f415bd7e5f81d | |
parent | 9643616d12e0617e1a48c680ccc5ec9a996ccdec (diff) | |
download | ohai-if/solaris-cpu.tar.gz |
update solaris cpu infoif/solaris-cpu
-rw-r--r-- | lib/ohai/plugins/solaris2/cpu.rb | 58 |
1 files changed, 44 insertions, 14 deletions
diff --git a/lib/ohai/plugins/solaris2/cpu.rb b/lib/ohai/plugins/solaris2/cpu.rb index 9900cd48..b321ed52 100644 --- a/lib/ohai/plugins/solaris2/cpu.rb +++ b/lib/ohai/plugins/solaris2/cpu.rb @@ -1,4 +1,6 @@ # +# Author:: Isa Farnik (isa@chef.io) +# Copyright:: Copyright (c) 2015 Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -19,23 +21,51 @@ Ohai.plugin(:CPU) do collect_data(:solaris2) do cpu Mash.new + cpu[:total] = shell_out("psrinfo | wc -l").stdout.to_i cpu[:real] = shell_out("psrinfo -p").stdout.to_i - processor_info = shell_out("psrinfo -v -p | grep Hz").stdout - processors = processor_info.split(/^ [^\s]/) - processors.each_with_index do |processor, i| - cpu_info, model_name = processor.split("\n ") - cpu_info = cpu_info.tr("()","").split - - index = i.to_s - cpu[index] = Mash.new - cpu[index]['vendor_id'] = cpu_info[1] - cpu[index]['family'] = cpu_info[4] - cpu[index]['model'] = cpu_info[6] - cpu[index]['stepping'] = cpu_info[8] - cpu[index]['model_name'] = model_name.strip - cpu[index]['mhz'] = cpu_info[10] + # CPU flags could be collected from: + # /usr/bin/isainfo -v + + # Cores and virtual processors can + # also be collected from psrinfo + # + # Tested against: + # - Sun-Fire-V245 + # - T5240 + # - Dell R610 + + # Matches: + # - model_name + # - chipid + # - vender_id + # - family + # - model + # - step + # - clock + # - intel-specific details + cpu_regex=%r{(?<proc_specs>(?<model_name>[^\s]*) \((?:.*?(?:chipid (?<chipid>\d+(?:x\d+)*),* )*.*?(?:(?<vender_id>GenuineIntel) )*.*?(?:.{5} )*.*?(?:family (?<family>\d+) )*.*?(?:model (?<model>\d+) )*.*?(?:step (?<step>\d+) )*)(?:clock (?<mhz>\d+) MHz).*?\))(?<alt_spec>(?:\n[\s\t]*(?<alt_model>(?<intel_model>.*?) CPU(?:[\s\t]{4,}).*?(?<intel_model_num>\w*)\s*.*?(?<ghz>\d+(?:\.\d+))GHz))*)*} + + cpu[:real].times do |cpu_slot| + processor_info = shell_out("psrinfo -v -p #{cpu_slot}").stdout + results = processor_info.match(cpu_regex) + cpu[cpu_slot.to_i] = Mash[ results.names.zip( results.captures ) ] + + # Replace the model name when CPU model + # is generic and CPU is Intel + if cpu[cpu_slot.to_i][:model_name] == 'x86' || cpu[cpu_slot.to_i][:alt_spec].include?("Intel") + replacement_model = cpu[cpu_slot.to_i][:alt_model].gsub(/\s{2,}/, ' ') + cpu[cpu_slot.to_i][:proc_specs].gsub(/x86/, replacement_model) + cpu[cpu_slot.to_i][:model_name] = "#{cpu[cpu_slot.to_i][:intel_model]} #{cpu[cpu_slot.to_i][:intel_model_num]}" + end + + # Clear empty values + cpu[cpu_slot.to_i].each do |key,value| + if value.nil? || value == "" + cpu[cpu_slot.to_i].delete(key) + end + end end end end |