add my new check_iowait

This commit is contained in:
Cyberes 2023-05-29 23:00:29 -06:00
parent 8156a95e05
commit f41e65c73c
1 changed files with 64 additions and 0 deletions

64
check_iowait_proc.sh Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
WARNING_THRESHOLD=10
CRITICAL_THRESHOLD=20
# Parse command line arguments
while getopts "w:c:" opt; do
case $opt in
w)
WARNING_THRESHOLD="$OPTARG"
;;
c)
CRITICAL_THRESHOLD="$OPTARG"
;;
\?)
echo "Usage: check_iowait.sh [-w warning_threshold] [-c critical_threshold]"
exit 1
;;
esac
done
if ! command -v iostat &>/dev/null; then
echo "iostat not found! Please install sysstat:"
echo "sudo apt install sysstat"
exit 1
fi
if ! command -v iotop &>/dev/null; then
echo "iotop not found! Please install sysstat:"
echo "sudo apt install iotop"
exit 1
fi
# Get iowait value
iowait=$(iostat -c | awk 'NR==4 {print $4}')
# Get process list header and top 3 processes causing iowait
header=$(iotop -b -n 1 -P -k -o | head -n 1)
top_processes=$(iotop -b -n 1 -P -k -o | tail -n +4 | head -n 3)
# Check if there are no processes causing iowait
if [ -z "$top_processes" ]; then
top_processes="No processes causing significant iowait."
else
top_processes="$header"$'\n'"$top_processes"
fi
iowait_str="- iowait: $iowait%"$'\n'"Top 3 processes causing iowait:"
perfdata="iowait=$iowait%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
# Check if iowait is above thresholds
if (( $(echo "$iowait > $CRITICAL_THRESHOLD" | bc -l) )); then
echo "CRITICAL $iowait_str"
echo "$top_processes | $perfdata"
exit 2
elif (( $(echo "$iowait > $WARNING_THRESHOLD" | bc -l) )); then
echo "WARNING $iowait_str"
echo "$top_processes | $perfdata"
exit 1
else
echo -e "OK $iowait_str"
echo "$top_processes | $perfdata"
exit 0
fi