check_iowait.sh avg over interval
This commit is contained in:
parent
7c73fbd4c2
commit
50e85bcd2c
|
@ -7,19 +7,25 @@ if ! command -v iostat &>/dev/null; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Nagios plugin to check iowait on Linux
|
||||||
|
|
||||||
# Define usage function
|
# Define usage function
|
||||||
function usage {
|
function usage {
|
||||||
echo "Usage: $0 [-w <warning threshold>] [-c <critical threshold>]"
|
echo "Usage: $0 [-w <warning threshold>] [-c <critical threshold>] [-a <average seconds>]"
|
||||||
echo " -w: Warning threshold for iowait percentage (default: 50)"
|
echo " -w: Warning threshold for iowait percentage (default: 50)"
|
||||||
echo " -c: Critical threshold for iowait percentage (default: 75)"
|
echo " -c: Critical threshold for iowait percentage (default: 75)"
|
||||||
|
echo " -a: Number of seconds to average iowait (default: 5)"
|
||||||
exit 3
|
exit 3
|
||||||
}
|
}
|
||||||
|
|
||||||
# Parse command line arguments
|
# Parse command line arguments
|
||||||
while getopts "w:c:" opt; do
|
while getopts "w:c:a:" opt; do
|
||||||
case $opt in
|
case $opt in
|
||||||
w) WARNING_THRESHOLD=$OPTARG ;;
|
w) WARNING_THRESHOLD=$OPTARG ;;
|
||||||
c) CRITICAL_THRESHOLD=$OPTARG ;;
|
c) CRITICAL_THRESHOLD=$OPTARG ;;
|
||||||
|
a) AVERAGE_SECONDS=$OPTARG ;;
|
||||||
\?)
|
\?)
|
||||||
echo "Invalid option: -$OPTARG" >&2
|
echo "Invalid option: -$OPTARG" >&2
|
||||||
usage
|
usage
|
||||||
|
@ -34,18 +40,24 @@ done
|
||||||
# Set default warning and critical thresholds if not provided
|
# Set default warning and critical thresholds if not provided
|
||||||
WARNING_THRESHOLD=${WARNING_THRESHOLD:-50}
|
WARNING_THRESHOLD=${WARNING_THRESHOLD:-50}
|
||||||
CRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:-75}
|
CRITICAL_THRESHOLD=${CRITICAL_THRESHOLD:-75}
|
||||||
|
AVERAGE_SECONDS=${AVERAGE_SECONDS:-5}
|
||||||
|
|
||||||
IOWAIT=$(iostat -c | awk '/^ /{print $4}')
|
# 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)
|
||||||
|
|
||||||
|
# Check if iowait percentage is above critical threshold
|
||||||
if (($(echo "$IOWAIT > $CRITICAL_THRESHOLD" | bc -l))); then
|
if (($(echo "$IOWAIT > $CRITICAL_THRESHOLD" | bc -l))); then
|
||||||
echo "CRITICAL - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
echo "CRITICAL - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100 processes=$PROCESSES"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if iowait percentage is above warning threshold
|
||||||
if (($(echo "$IOWAIT > $WARNING_THRESHOLD" | bc -l))); then
|
if (($(echo "$IOWAIT > $WARNING_THRESHOLD" | bc -l))); then
|
||||||
echo "WARNING - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
echo "WARNING - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100 processes=$PROCESSES"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "OK - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100"
|
# If iowait percentage is below warning threshold, exit with OK status
|
||||||
|
echo "OK - iowait percentage is $IOWAIT% | iowait=$IOWAIT%;$WARNING_THRESHOLD;$CRITICAL_THRESHOLD;0;100 processes=$PROCESSES"
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Reference in New Issue