Skip to content

Instantly share code, notes, and snippets.

@ross-nordstrom
Last active August 29, 2015 14:07
Show Gist options
  • Save ross-nordstrom/e3e65209852aac74fe4b to your computer and use it in GitHub Desktop.
Save ross-nordstrom/e3e65209852aac74fe4b to your computer and use it in GitHub Desktop.
Get a breakdown of CPU temperatures. Requires `sudo apt-get install lm-sensors && sudo sensors-detect`
#!/usr/bin/env ruby
require 'json'
temps = `sensors`
tempLines = temps.split("\n").select{|l| l.include?('Core') }
max = 0
tempData = tempLines.map{|l| [ l.split(':')[0].split(' ').join(''), l.split('+')[1].split('C')[0][0..-2] ] }.reduce({}) do |acc, l|
acc[l[0]] = l[1].to_f
max = [acc[l[0]], max].max
acc
end
tempData['max'] = max
puts tempData.to_json.gsub(/"/, "'")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment