2023-06-07 14:31:09 -06:00
|
|
|
#!/usr/bin/env 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-06-07 14:31:09 -06:00
|
|
|
#!/usr/bin/env bash
|
2023-04-21 23:54:18 -06:00
|
|
|
|
|
|
|
# Nagios plugin to check iowait on Linux
|
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
# Define usage function
|
|
|
|
function usage {
|
2023-04-21 23:54:18 -06:00
|
|
|
echo "Usage: $0 [-w <warning threshold>] [-c <critical threshold>] [-a <average seconds>]"
|
2023-04-21 23:54:18 -06:00
|
|
|
echo " -w: Warning threshold for iowait percentage (default: 50)"
|
|
|
|
echo " -c: Critical threshold for iowait percentage (default: 75)"
|
2023-04-21 23:54:18 -06:00
|
|
|
echo " -a: Number of seconds to average iowait (default: 5)"
|
2023-04-21 23:54:18 -06:00
|
|
|
exit 3
|
|
|
|
}
|
|
|
|
|
|
|
|
# Parse command line arguments
|
2023-04-21 23:54:18 -06:00
|
|
|
while getopts "w:c:a:" opt; do
|
2023-04-21 23:54:18 -06:00
|
|
|
case $opt in
|
|
|
|
w) WARNING_THRESHOLD=$OPTARG ;;
|
|
|
|
c) CRITICAL_THRESHOLD=$OPTARG ;;
|
2023-04-21 23:54:18 -06:00
|
|
|
a) AVERAGE_SECONDS=$OPTARG ;;
|
2023-04-21 23:54:18 -06:00
|
|
|
\?)
|
|
|
|
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}
|
2023-04-21 23:54:18 -06:00
|
|
|
AVERAGE_SECONDS=${AVERAGE_SECONDS:-5}
|
2023-04-21 23:54:18 -06:00
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
# Get current iowait percentage and number of processes
|
|
|
|
IOWAIT=$(iostat -c $AVERAGE_SECONDS 2 | awk '/^ /{print $4}' | tail -n 1)
|
|
|
|
PROCESSES=$(ps -A --no-headers | wc -l)
|
2023-04-21 23:54:18 -06:00
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
# Check if iowait percentage is above critical threshold
|
2023-04-21 23:54:18 -06:00
|
|
|
if (($(echo "$IOWAIT > $CRITICAL_THRESHOLD" | bc -l))); then
|
2023-04-21 23:54:18 -06:00
|
|
|
echo "CRITICAL - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
2023-04-21 23:54:18 -06:00
|
|
|
exit 2
|
2023-04-21 23:54:18 -06:00
|
|
|
fi
|
2023-04-21 23:54:18 -06:00
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
# Check if iowait percentage is above warning threshold
|
2023-04-21 23:54:18 -06:00
|
|
|
if (($(echo "$IOWAIT > $WARNING_THRESHOLD" | bc -l))); then
|
2023-04-21 23:54:18 -06:00
|
|
|
echo "WARNING - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
2023-04-21 23:54:18 -06:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-04-21 23:54:18 -06:00
|
|
|
# If iowait percentage is below warning threshold, exit with OK status
|
2023-04-21 23:54:18 -06:00
|
|
|
echo "OK - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
2023-04-21 23:54:18 -06:00
|
|
|
exit 0
|