Autoconfigure sensible labels for Intel coretemp sensors
authorTom Hughes <tom@compton.nu>
Mon, 5 Oct 2015 08:26:51 +0000 (09:26 +0100)
committerTom Hughes <tom@compton.nu>
Mon, 5 Oct 2015 08:32:39 +0000 (09:32 +0100)
cookbooks/hardware/recipes/default.rb

index 2938b763ce9ea0b531a5b57836b75a8ce12b30c8..9e1af16efb78c7cda552a0d0744764a0489a7502 100644 (file)
@@ -536,6 +536,24 @@ end
 unless Dir.glob("/sys/class/hwmon/hwmon*").empty?
   package "lm-sensors"
 
+  Dir.glob("/sys/devices/platform/coretemp.*").each do |coretemp|
+    cpu = File.basename(coretemp).sub("coretemp.", "").to_i
+    chip = format("coretemp-isa-%04d", cpu)
+
+    temps = Dir.glob("#{coretemp}/temp*_input").map do |temp|
+      File.basename(temp).sub("temp", "").sub("_input", "").to_i
+    end.sort
+
+    if temps.first == 1
+      node.default[:hardware][:sensors][chip][:temps][:temp1][:label] = "CPU #{cpu}"
+      temps.shift
+    end
+
+    temps.each_with_index do |temp, index|
+      node.default[:hardware][:sensors][chip][:temps]["temp#{temp}"][:label] = "CPU #{cpu} Core #{index}"
+    end
+  end
+
   execute "/etc/sensors.d/chef.conf" do
     action :nothing
     command "/usr/bin/sensors -s"