check_iowait.sh from chatgpt
This commit is contained in:
parent
f37e260d7b
commit
7c73fbd4c2
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# Nagios plugin to check iowait on Linux
|
||||||
|
|
||||||
if ! command -v iostat &>/dev/null; then
|
if ! command -v iostat &>/dev/null; then
|
||||||
echo "iostat not found! Please install sysstat:"
|
echo "iostat not found! Please install sysstat:"
|
||||||
|
@ -6,27 +7,45 @@ if ! command -v iostat &>/dev/null; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$1" = "-w" ] && [ "$2" -gt "0" ] && [ "$3" = "-c" ] && [ "$4" -gt "0" ]; then
|
# Define usage function
|
||||||
IOWAIT=$(iostat | sed -n "4p" | awk {'print $4'} | cut -d. -f1)
|
function usage {
|
||||||
if [ "$IOWAIT" -ge "$4" ]; then
|
echo "Usage: $0 [-w <warning threshold>] [-c <critical threshold>]"
|
||||||
echo "IO Wait: CRITICAL - $IOWAIT % |IOWAIT=$IOWAIT;;;;"
|
echo " -w: Warning threshold for iowait percentage (default: 50)"
|
||||||
exit 2
|
echo " -c: Critical threshold for iowait percentage (default: 75)"
|
||||||
elif [ "$IOWAIT" -ge "$2" ]; then
|
exit 3
|
||||||
echo "IO Wait: WARNING - $IOWAIT % |IOWAIT=$IOWAIT;;;;"
|
}
|
||||||
exit 1
|
|
||||||
else
|
# Parse command line arguments
|
||||||
echo "IO Wait: OK - $IOWAIT % |IOWAIT=$IOWAIT;;;;"
|
while getopts "w:c:" opt; do
|
||||||
exit 0
|
case $opt in
|
||||||
fi
|
w) WARNING_THRESHOLD=$OPTARG ;;
|
||||||
else
|
c) CRITICAL_THRESHOLD=$OPTARG ;;
|
||||||
echo "$0 v1.0"
|
\?)
|
||||||
echo ""
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
echo "Usage:"
|
usage
|
||||||
echo "$0 -w <warnlevel> -c <critlevel>"
|
;;
|
||||||
echo ""
|
:)
|
||||||
echo "warnlevel and critlevel is percentage value without %"
|
echo "Option -$OPTARG requires an argument." >&2
|
||||||
echo "
|
usage
|
||||||
echo "EXAMPLE: check_iowait -w 90 -c 95
|
;;
|
||||||
echo ""
|
esac
|
||||||
exit
|
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
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
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
|
||||||
|
|
Loading…
Reference in New Issue