Hardware Monitoring: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Wulf (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
Wulf (Diskussion | Beiträge) Keine Bearbeitungszusammenfassung |
||
| Zeile 4: | Zeile 4: | ||
# | # | ||
# Author: Frank Wulf | # Author: Frank Wulf | ||
# Version: 1. | # Version: 1.1 (2018-09-07) | ||
# | # | ||
# This program detects the following system values and writes | # This program detects the following system values and writes | ||
| Zeile 15: | Zeile 15: | ||
# Version history: | # Version history: | ||
# 1.0 2017-10-04 Initial release | # 1.0 2017-10-04 Initial release | ||
# 1.1 2018-09-07 Replaced pcsensor program with newer version | |||
# | # | ||
# Offset for room temperature sensor ( | # Offset for room temperature sensor (value will be subtracted from Celsius) | ||
calib= | calib=2 | ||
# Minimum percentage of CPU usage for processes shown in comment field | # Minimum percentage of CPU usage for processes shown in comment field | ||
| Zeile 85: | Zeile 86: | ||
for i in {1..5} | for i in {1..5} | ||
do | do | ||
temp_room=`pcsensor - | temp_room=`pcsensor -s$calib` | ||
if [ $temp_room == " | if [ "$temp_room" == "" ]; then | ||
# Wait five seconds and try again | # Wait five seconds and try again | ||
sleep 5 | sleep 5 | ||
Version vom 7. September 2018, 22:52 Uhr
Shell script /usr/bin/fwsysmon:
#!/bin/bash
#
# Author: Frank Wulf
# Version: 1.1 (2018-09-07)
#
# This program detects the following system values and writes
# them into a database:
# - Temperatures of room, mainboard, CPU and hard disks
# - Status of hard disks (active or sleeping)
# - Fan speeds
# - System load
#
# Version history:
# 1.0 2017-10-04 Initial release
# 1.1 2018-09-07 Replaced pcsensor program with newer version
#
# Offset for room temperature sensor (value will be subtracted from Celsius)
calib=2
# Minimum percentage of CPU usage for processes shown in comment field
tmin=10
# Determine load average for last 1, 5 and 15 minutes
i=0
for loadavg in `cat /proc/loadavg`; do
let i+=1
if [ $i -le 3 ]; then load[$i]=$loadavg; fi
done
# Build comment field with processes reaching minimum percentage
i=0
while read process; do
let i+=1
tpcnt[$i]=`echo "$process"|awk '{printf $9}'`
tproc[$i]=`echo "$process"|awk '{printf $12}'`
if (( $(echo "${tpcnt[$i]} >= $tmin" | bc -l) )); then
if [ $i -eq 1 ]; then
comment="${tpcnt[$i]}%=${tproc[$i]};"
else
comment="${comment} ${tpcnt[$i]}%=${tproc[$i]};"
fi
fi
done <<<`top -b -n 1|grep -v "top$"|tail -n +8|head -n 4`
# Get status and temperatures of hard disks
i=0
while read temp; do
let i+=1
if `echo $temp|grep -qv "sleeping"`; then
status_hdd[$i]="Active"
temp_hdd[$i]=`echo $temp|cut -c1-2`
else
status_hdd[$i]="Sleeping"
temp_hdd[$i]=0
fi
done <<<`hddtemp /dev/sd? 2>&1|grep "^/dev"|grep -v "sda"|sort|cut -d: -f3|cut -c2-`
while [ $i -lt 5 ]; do
let i+=1
status_hdd[$i]="Not available"
temp_hdd[$i]=0
done
# Get system temperatures and fan speeds
while read line; do
case `echo $line|cut -d: -f1` in
"SYSTIN") temp_sys=`echo "$line"|cut -c26-29`;;
"CPUTIN") temp_cpu_ext=`echo "$line"|cut -c26-29`;;
"Package id 0") temp_cpu_int=`echo "$line"|cut -c17-20`;;
"Core 0") temp_core0=`echo "$line"|cut -c17-20`;;
"Core 1") temp_core1=`echo "$line"|cut -c17-20`;;
"Core 2") temp_core2=`echo "$line"|cut -c17-20`;;
"Core 3") temp_core3=`echo "$line"|cut -c17-20`;;
"fan1") speed_fan1=`echo "$line"|cut -c24-28`;;
"fan2") speed_fan2=`echo "$line"|cut -c24-28`;;
"fan3") speed_fan3=`echo "$line"|cut -c24-28`;;
"fan4") speed_fan4=`echo "$line"|cut -c24-28`;;
"fan5") speed_fan5=`echo "$line"|cut -c24-28`;;
esac
done <<<`sensors -A nct6791-isa-0290 coretemp-isa-0000`
# Get room temperature (up to 5 attempts)
for i in {1..5}
do
temp_room=`pcsensor -s$calib`
if [ "$temp_room" == "" ]; then
# Wait five seconds and try again
sleep 5
else
break
fi
done
# Fill timestamp field
timestamp=`date +'%Y-%m-%d %H:%M:%S'`
# Insert data into database
mysql --login-path=fwsysmon -D fwsysmon <<EOF
INSERT INTO fw_values (timestamp,temp_room,temp_sys,temp_cpu_ext,temp_cpu_int,temp_core0,temp_core1,temp_core2,temp_core3,status_hdd1,status_hdd2,status_hdd3,status_hdd4,status_hdd5,temp_hdd1,temp_hdd2,temp_hdd3,temp_hdd4,temp_hdd5,speed_fan1,speed_fan2,speed_fan3,speed_fan4,speed_fan5,load01,load05,load15,comment) VALUES ("$timestamp", "$temp_room", "$temp_sys", "$temp_cpu_ext", "$temp_cpu_int", "$temp_core0", "$temp_core1", "$temp_core2", "$temp_core3", "${status_hdd[1]}", "${status_hdd[2]}", "${status_hdd[3]}", "${status_hdd[4]}", "${status_hdd[5]}", "${temp_hdd[1]}", "${temp_hdd[2]}", "${temp_hdd[3]}", "${temp_hdd[4]}", "${temp_hdd[5]}", "$speed_fan2", "$speed_fan3", "$speed_fan4", "$speed_fan1", "$speed_fan5", "${load[1]}", "${load[2]}", "${load[3]}", "$comment")
EOF