Health2MySQL

From wiki.welmers.net

Jump to: navigation, search

Simple script for writing health statistics to a MySQL table.

#!/bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

database=health
table=health_myserver

rpm_fan=`sensors | grep "fan1" | cut -f6 -d" "`
temp_mb=`sensors | grep "M/B Temp" | cut -f6 -d" "`
temp_cpu=`sensors | grep "CPU Temp" | cut -f6 -d" "`
temp_sda=`hddtemp /dev/sda | cut -f3 -d":" | cut -f2 -d" "`
temp_sdb=`hddtemp /dev/sdb | cut -f3 -d":" | cut -f2 -d" "`


echo "INSERT INTO $table (datetime, rpm_fan, temp_mb, temp_cpu, temp_sda, temp_sdb) VALUES (NOW(), '$rpm_fan', '$temp_mb', '$temp_cpu', '$temp_sda', '$temp_sdb')" | mysql $database

Use ~/.my.cnf to configure MySQL access:

[client]
user=myserver
host=192.168.71.80
password=mypassword

Use cron (crontab -e) to run it i.e. once a minute:

# m h  dom mon dow   command
  * *   *   *   *    /usr/local/sbin/health.sh

Next thing on the TODO list is writing scripts to analyse the data gathered in the MySQL table.

Personal tools