2023-04-21 23:54:18 -06:00
|
|
|
#!/bin/bash
|
2023-04-21 23:54:18 -06:00
|
|
|
# Nagios plugin to check iowait on Linux
|
2023-04-21 23:54:18 -06:00
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
if ! command -v iostat &>/dev/null; then
|
|
|
|
echo "iostat not found! Please install sysstat:"
|
|
|
|
echo "sudo apt install sysstat"
|
|
|
|
exit 1
|
2023-04-21 23:54:18 -06:00
|
|
|
fi
|
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
# Define usage function
|
|
|
|
function usage {
|
|
|
|
echo "Usage: $0 [-w <warning threshold>] [-c <critical threshold>]"
|
|
|
|
echo " -w: Warning threshold for iowait percentage (default: 50)"
|
|
|
|
echo " -c: Critical threshold for iowait percentage (default: 75)"
|
|
|
|
exit 3
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse command line arguments
|
|
|
|
while getopts "w:c:" opt; do
|
|
|
|
case $opt in
|
|
|
|
w) WARNING_THRESHOLD=$OPTARG ;;
|
|
|
|
c) CRITICAL_THRESHOLD=$OPTARG ;;
|
|
|
|
\?)
|
|
|
|
echo "Invalid option: -$OPTARG" >&2
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
:)
|
|
|
|
echo "Option -$OPTARG requires an argument." >&2
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
# Set default warning and critical thresholds if not provided
|
|
|
|
WARNING_THRESHOLD=${WARNING_THRESHOLD:-50}
|
|
|
|
CRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:-75}
|
|
|
|
|
|
|
|
IOWAIT=$(iostat -c | awk '/^ /{print $4}')
|
|
|
|
|
|
|
|
if (($(echo "$IOWAIT > $CRITICAL_THRESHOLD" | bc -l))); then
|
|
|
|
echo "CRITICAL - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
|
|
|
exit 2
|
2023-04-21 23:54:18 -06:00
|
|
|
fi
|
2023-04-21 23:54:18 -06:00
|
|
|
|
|
|
|
if (($(echo "$IOWAIT > $WARNING_THRESHOLD" | bc -l))); then
|
|
|
|
echo "WARNING - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "OK - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
|
|
|
exit 0
|