blob: 56f8d9d01500d60642f770a6ff4561492ea2aa49 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
|