diff options
| author | Felix Hanley <felix@userspace.com.au> | 2022-02-15 11:29:57 +0000 |
|---|---|---|
| committer | Felix Hanley <felix@userspace.com.au> | 2022-02-15 11:29:57 +0000 |
| commit | 6e9ad685b7f8ec16a3f3a2d6875fba530bcaa715 (patch) | |
| tree | 7fe5c5052282e5e595d4f85c722f511a79f0ddf6 /smartmon.sh | |
| download | collectd-freebsd-6e9ad685b7f8ec16a3f3a2d6875fba530bcaa715.tar.gz collectd-freebsd-6e9ad685b7f8ec16a3f3a2d6875fba530bcaa715.tar.bz2 | |
Diffstat (limited to 'smartmon.sh')
| -rwxr-xr-x | smartmon.sh | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/smartmon.sh b/smartmon.sh new file mode 100755 index 0000000..56f8d9d --- /dev/null +++ b/smartmon.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +PATH=/bin:/sbin:/usr/bin/:/usr/sbin:/usr/local/bin/:/usr/local/sbin +HOSTNAME="${COLLECTD_HOSTNAME:-localhost}" +INTERVAL="${COLLECTD_INTERVAL:-120}" + +AWKOPTS="-v interval=${INTERVAL} -v host=${HOSTNAME}" + +# Typical output: +# PUTVAL <host>/smartmon-sda4/gauge-raw_read_error_rate interval=300 N:30320489 +# PUTVAL <host>/smartmon-sda4/gauge-spin_up_time interval=300 N:0 +# PUTVAL <host>/smartmon-sda4/gauge-reallocated_sector_count interval=300 N:472 +# PUTVAL <host>/smartmon-sda4/gauge-end_to_end_error interval=300 N:0 +# PUTVAL <host>/smartmon-sda4/gauge-reported_uncorrect interval=300 N:1140 +# PUTVAL <host>/smartmon-sda4/gauge-command_timeout interval=300 N:85900918876 +# PUTVAL <host>/smartmon-sda4/temperature-airflow interval=300 N:31 +# PUTVAL <host>/smartmon-sda4/temperature-temperature interval=300 N:31 +# PUTVAL <host>/smartmon-sda4/gauge-offline_uncorrectable interval=300 N:5 +# PUTVAL <host>/smartmon-sdb/gauge-raw_read_error_rate interval=300 N:0 +# PUTVAL <host>/smartmon-sdb/gauge-spin_up_time interval=300 N:4352 +# ... + +while true; do + for disk in $(sysctl -n kern.disks |awk '{for (i=NF; i!=0 ; i--) if(match($i, '/ada/')) print $i }' ); do + + eval $(doas smartctl -A "/dev/$disk" |awk ${AWKOPTS} -v disk=$disk '$3 ~ /^0x/ && $2 ~ /^[a-zA-Z0-9_-]+$/ { gsub(/-/, "_"); print "SMART_" $2 "=" $10 }' 2>/dev/null) + + [ -n "$SMART_Command_Timeout" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-command_timeout interval=$INTERVAL N:${SMART_Command_Timeout:-U}" + [ -n "$SMART_Current_Pending_Sector" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-current_pending_sector interval=$INTERVAL N:${SMART_Current_Pending_Sector:-U}" + [ -n "$SMART_End_to_End_Error" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-end_to_end_error interval=$INTERVAL N:${SMART_End_to_End_Error:-U}" + [ -n "$SMART_Hardware_ECC_Recovered" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-hardware_ecc_recovered interval=$INTERVAL N:${SMART_Hardware_ECC_Recovered:-U}" + [ -n "$SMART_Offline_Uncorrectable" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-offline_uncorrectable interval=$INTERVAL N:${SMART_Offline_Uncorrectable:-U}" + [ -n "$SMART_Raw_Read_Error_Rate" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-raw_read_error_rate interval=$INTERVAL N:${SMART_Raw_Read_Error_Rate:-U}" + [ -n "$SMART_Reallocated_Sector_Ct" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-reallocated_sector_count interval=$INTERVAL N:${SMART_Reallocated_Sector_Ct:-U}" + [ -n "$SMART_Reported_Uncorrect" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-reported_uncorrect interval=$INTERVAL N:${SMART_Reported_Uncorrect:-U}" + [ -n "$SMART_Spin_Up_Time" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-spin_up_time interval=$INTERVAL N:${SMART_Spin_Up_Time:-U}" + [ -n "$SMART_Airflow_Temperature_Cel" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/temperature-airflow interval=$INTERVAL N:${SMART_Airflow_Temperature_Cel:-U}" + [ -n "$SMART_Temperature_Celsius" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/temperature-temperature interval=$INTERVAL N:${SMART_Temperature_Celsius:-U}" + [ -n "$SMART_Media_Wearout_Indicator" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-media_wearout_indicator interval=$INTERVAL N:${SMART_Media_Wearout_Indicator:-U}" + [ -n "$SMART_Load_Cycle_Count" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-load_cycle_count interval=$INTERVAL N:${SMART_Load_Cycle_Count:-U}" + [ -n "$SMART_Power_Cycle_Count" ] && + echo "PUTVAL $HOSTNAME/smartmon-$disk/gauge-power_cycle_count interval=$INTERVAL N:${SMART_Power_Cycle_Count:-U}" + done + + sleep $INTERVAL || true +done |
