trevellyan

FreeNAS CPU and drive temperatures

Jan 29th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.12 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #
  3. # FreeNAS CPU and drive temperatures
  4. # based on a shell script by @Bidule0hm
  5.  
  6. import subprocess
  7.  
  8. ncpu = int(subprocess.check_output(['sysctl', '-n', 'hw.ncpu']))
  9.  
  10. for cpu in range(ncpu):
  11.     temperature = subprocess.check_output(
  12.         ['sysctl', '-n', 'dev.cpu.'+str(cpu)+'.temperature']
  13.         )
  14.     print 'CPU {0}: {1}'.format(cpu, temperature),
  15.  
  16. drives = subprocess.check_output(['sysctl', '-n', 'kern.disks']).split()
  17. drives.sort()
  18.  
  19. for drive in drives:
  20.     # get SMART data if available
  21.     try:
  22.         smart = subprocess.check_output(['smartctl', '-a', '/dev/'+drive]).splitlines()
  23.  
  24.         serial = filter(
  25.             lambda line: 'umber' in line,
  26.             smart
  27.             )[0]
  28.         serial = serial.split()[-1]+':'
  29.  
  30.         temperature = filter(
  31.             lambda line: 'Temperature_Celsius' in line,
  32.             smart
  33.             )[0]
  34.         temperature = temperature.split(None, 9)[9]
  35.  
  36.     # SMART not supported, or error?
  37.     except subprocess.CalledProcessError as result:
  38.         serial = 'N/A'
  39.         temperature = ''
  40.  
  41.     print drive, serial, temperature
Add Comment
Please, Sign In to add comment