From 9abb4468006c51c9b6971e58d220f827be7d7051 Mon Sep 17 00:00:00 2001 From: curiositycasualty Date: Fri, 13 Mar 2015 11:29:14 -0400 Subject: update solaris cpu info --- lib/ohai/plugins/solaris2/cpu.rb | 58 ++++++++++++++++++++++++++++++---------- 1 file 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{(?(?[^\s]*) \((?:.*?(?:chipid (?\d+(?:x\d+)*),* )*.*?(?:(?GenuineIntel) )*.*?(?:.{5} )*.*?(?:family (?\d+) )*.*?(?:model (?\d+) )*.*?(?:step (?\d+) )*)(?:clock (?\d+) MHz).*?\))(?(?:\n[\s\t]*(?(?.*?) CPU(?:[\s\t]{4,}).*?(?\w*)\s*.*?(?\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 -- cgit v1.2.1