aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hanley <felix@userspace.com.au>2022-02-15 11:29:57 +0000
committerFelix Hanley <felix@userspace.com.au>2022-02-15 11:29:57 +0000
commit6e9ad685b7f8ec16a3f3a2d6875fba530bcaa715 (patch)
tree7fe5c5052282e5e595d4f85c722f511a79f0ddf6
downloadcollectd-freebsd-6e9ad685b7f8ec16a3f3a2d6875fba530bcaa715.tar.gz
collectd-freebsd-6e9ad685b7f8ec16a3f3a2d6875fba530bcaa715.tar.bz2
Extract existing scriptsHEADmaster
-rw-r--r--README.md3
-rwxr-xr-xnfsd.sh23
-rwxr-xr-xsmartmon.sh59
-rwxr-xr-xtemperatures.sh29
4 files changed, 114 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..3d880c7
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# Collectd scripts
+
+A collection of collectd collection scripts for FreeBSD.
diff --git a/nfsd.sh b/nfsd.sh
new file mode 100755
index 0000000..0faffb3
--- /dev/null
+++ b/nfsd.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+
+PATH=
+SLEEP=/bin/sleep
+DOAS=/usr/local/bin/doas
+AWK=/usr/bin/awk
+NFSSTAT=/usr/bin/nfsstat
+JQ=/usr/local/bin/jq
+
+HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
+INTERVAL="${COLLECTD_INTERVAL:-120}"
+
+AWKOPTS="-v interval=${INTERVAL} -v host=${HOSTNAME}"
+
+while true; do
+ $DOAS $NFSSTAT --libxo json \
+ | $JQ -r '.nfsstat.serverstats.operations | keys[] as $k | "\($k)=\(.[$k])"' \
+ | $AWK ${AWKOPTS} -F "[.=]" '{printf "PUTVAL %s/nfs_server-operation/gauge-%s interval=%s N:%d\n", host, $1, interval, int($2)}'
+ $DOAS $NFSSTAT --libxo json \
+ | $JQ -r '.nfsstat.serverstats.cache | keys[] as $k | "\($k)=\(.[$k])"' \
+ | $AWK ${AWKOPTS} -F "[.=]" '{printf "PUTVAL %s/nfs_server-cache/gauge-%s interval=%s N:%d\n", host, $1, interval, int($2)}'
+ $SLEEP $INTERVAL
+done
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
diff --git a/temperatures.sh b/temperatures.sh
new file mode 100755
index 0000000..48a4d55
--- /dev/null
+++ b/temperatures.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+PATH=
+SLEEP=/bin/sleep
+DOAS=/usr/local/bin/doas
+AWK=/usr/bin/awk
+SYSCTL=/sbin/sysctl
+SMARTCTL=/usr/local/sbin/smartctl
+
+HOSTNAME="${COLLECTD_HOSTNAME:-localhost}"
+INTERVAL="${COLLECTD_INTERVAL:-120}"
+
+AWKOPTS="-v interval=${INTERVAL} -v host=${HOSTNAME}"
+
+while true; do
+
+ $SYSCTL -e dev.cpu \
+ | $AWK ${AWKOPTS} -F '[.=]' '/temperature/ {printf "PUTVAL %s/thermal/temperature-cpu%s interval=%s N:%d\n", host, $3, interval, int($5)}'
+
+ $SYSCTL -e hw.acpi.thermal \
+ | $AWK ${AWKOPTS} -F "[.=]" '/temperature/ {printf "PUTVAL %s/thermal/temperature-%s interval=%s N:%d\n", host, $4, interval, int($6)}'
+
+ for i in $($SYSCTL -n kern.disks | $AWK '{for (i=NF; i!=0 ; i--) if(match($i, '/ada/')) print $i }' ); do
+ $DOAS $SMARTCTL -a -n standby /dev/$i \
+ | $AWK ${AWKOPTS} -v disk=$i '/Temperature_Celsius/ {printf "PUTVAL %s/thermal/temperature-%s interval=%s N:%s\n", host, disk, interval, $10}'
+ done
+
+ $SLEEP $INTERVAL
+done