Files
opt/collectd/usr/local/bin/temperature-data
2024-11-27 10:16:41 +01:00

44 lines
742 B
Python
Executable File

#!/usr/bin/python -u
#
# Imports
#
import sys
import time
import commands
import argparse
#
# Methods
#
def get_temperature(disks):
command = "sudo smartctl -a /dev/%s | grep Temperature_Celsius | awk '{print $10}'" % disk
status, output = commands.getstatusoutput(command)
try:
return int(output)
except Exception as e:
return None
#
# Settings
#
hostname = 'server'
interval = 10
disks = ['sdd', 'sde', 'sdf']
#
# 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)