Skip to content

Instantly share code, notes, and snippets.

@omasanori
Last active June 22, 2018 10:18
Show Gist options
  • Save omasanori/c71748d2373bc8a761b08aee8bab367c to your computer and use it in GitHub Desktop.
Save omasanori/c71748d2373bc8a761b08aee8bab367c to your computer and use it in GitHub Desktop.
Monitor the temparture of processors on Linux
#!/usr/bin/env python3
def get_temp(socket_id):
thermal_zone = '/sys/class/thermal/thermal_zone' + socket_id
with open(thermal_zone + '/temp') as temp:
return int(temp.read()) / 1000.0 # + 273.15
if __name__ == '__main__':
import json
import sys
if len(sys.argv) == 1:
print('''Usage: monitor_temp.py socket_id [socket_id...]
Examples:
$ monitor_temp.py 0 # monitor processor 0
$ monitor_temp.py 0 2 # 3P or more, 2 of them will be monitored
''')
sys.exit('Please specify sockets to be monitored.')
temps = {}
for socket_id in sys.argv[1:]:
temps['socket' + socket_id] = get_temp(socket_id)
print(json.dumps(temps))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment