42 lines
808 B
Python
Executable File
42 lines
808 B
Python
Executable File
#!/usr/bin/python3
|
|
|
|
#
|
|
# Imports
|
|
#
|
|
import sys
|
|
import time
|
|
import argparse
|
|
import subprocess
|
|
|
|
#
|
|
# Methods
|
|
#
|
|
def get_temperature(disks):
|
|
command = "sudo smartctl -a /dev/%s | grep Temperature_Celsius | awk '{print $10}'" % disk
|
|
result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
|
|
|
|
try:
|
|
return int(result.stdout)
|
|
except Exception as e:
|
|
return None
|
|
|
|
|
|
#
|
|
# Settings
|
|
#
|
|
hostname = 'shuttle'
|
|
interval = 10
|
|
disks = ['sda', 'sdb', 'sdc', 'sdd']
|
|
|
|
|
|
#
|
|
# Main
|
|
#
|
|
while True:
|
|
timestamp = int(time.time())
|
|
for disk in disks:
|
|
temperature = get_temperature(disk)
|
|
if temperature:
|
|
print('PUTVAL {}/exec-temperature/gauge-{}_total {}:{}'.format(hostname, disk, timestamp, temperature))
|
|
time.sleep(interval)
|