Sensu Check Scripts

Check CPU Temp – check_cpu_temp.sh

#!/bin/bash
host=$(hostname)
 echo "clients.$host.cpu-temp" $1 "`echo $'scale=2\n'$(cat /sys/class/thermal/thermal_zone0/temp)/1000 | bc`" $1 "`date +%s`"
 exit
:
fi

 

Check load – one minute – check_load_onemin.sh

#!/bin/bash
host=$(hostname)
 echo "clients.$host.load-onemin" $1 "`uptime | awk '{print $10}' | cut -d "," -f 1`" $1 "`date +%s`"
 exit
:
fi

 

An alternative for checking the load as sometimes the above script may print the previous column depending on the output of the day/time.

#!/bin/bash
host=$(hostname)
 echo "clients.$host.load-onemin" $1 "`uptime | awk '{print $(NF-2)}' | sed 's/,/ /g'`" $1 "`date +%s`"
 exit
:
fi

 

Check temperature (Raspberry Pi Temp Sensor) check_temp01.sh

#!/bin/bash
host=$(hostname)
temp=$(cat /sys/bus/w1/devices/28-0517c11b86ff/w1_slave | grep t= | awk '{print $10}' | tr -d 't,=' | sed -e "s/\b[0-9][0-9]/&./g")
tempf=$(echo "(1.8 * $temp) + 32" |bc)
echo "clients.$host.temp01" $1 "$tempf" $1 "`date +%s`"
exit
:
fi

 

Check memory – check_mem.sh

#!/bin/bash
host=$(hostname)
TOT=`cat /proc/meminfo | grep MemTotal: | awk '{print $2}'`
USED=`cat /proc/meminfo | grep Active: | awk '{print $2}'`
FREE=$[$TOT - $USED ]
LOG=/tmp/mem_monitor.log
echo > $LOG
SEND=0
if [ "$USED" -gt "0" ]; then
 USEDPERC=$[$USED * 100 / $TOT]
 echo "clients.$host.mem-used" $1 "$USEDPERC" $1 "`date +%s`"
 TOTMB=$[$TOT / 1024 ]
 USEDMB=$[$USED / 1024 ]
 FREEMB=$[$TOTMB - $USEDMB ]
fi