| Server IP : 172.64.80.1 / Your IP : 216.73.216.175 Web Server : LiteSpeed System : Linux srv13.swhc.ca 4.18.0-553.126.2.lve.el8.x86_64 #1 SMP Thu May 28 14:12:30 UTC 2026 x86_64 User : hongluck ( 2522) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /lib64/nagios/plugins/ |
Upload File : |
#!/bin/bash
iostat=`which iostat 2>/dev/null`
bc=`which bc 2>/dev/null`
function help {
echo -e "\n\tThis plugin shows the I/O usage of the specified disk, using the iostat external program.\n\tIt prints three statistics: Transactions per second (tps), Kilobytes per second\n\tread from the disk (KB_read/s) and and written to the disk (KB_written/s)\n\n$0:\n\t-c <tps>,<read>,<wrtn>\tSets the CRITICAL level for tps, KB_read/s and KB_written/s, respectively\n\t-w <tps>,<read>,<wrtn>\tSets the WARNING level for tps, KB_read/s and KB_written/s, respectively\n"
exit -1
}
# Ensuring we have the needed tools:
( [ ! -f $iostat ] || [ ! -f $bc ] ) && \
( echo "ERROR: You must have iostat and bc installed in order to run this plugin" && exit -1 )
# Getting parameters:
while getopts "d:w:c:h" OPT; do
case $OPT in
"w") warning=$OPTARG;;
"c") critical=$OPTARG;;
"h") help;;
esac
done
# Adjusting the three warn and crit levels:
crit_tps=`echo $critical | cut -d, -f1`
crit_read=`echo $critical | cut -d, -f2`
crit_written=`echo $critical | cut -d, -f3`
warn_tps=`echo $warning | cut -d, -f1`
warn_read=`echo $warning | cut -d, -f2`
warn_written=`echo $warning | cut -d, -f3`
# Checking parameters:
( [ "$warn_tps" == "" ] || [ "$warn_read" == "" ] || [ "$warn_written" == "" ] || \
[ "$crit_tps" == "" ] || [ "$crit_read" == "" ] || [ "$crit_written" == "" ] ) &&
echo "ERROR: You must specify all warning and critical levels" && help
( [[ "$warn_tps" -ge "$crit_tps" ]] || \
[[ "$warn_read" -ge "$crit_read" ]] || \
[[ "$warn_written" -ge "$crit_written" ]] ) && \
echo "ERROR: critical levels must be highter than warning levels" && help
tps=0
kbread=0
kbwritten=0
stats=`iostat -d -k | tail -n +4 | head -n -1`
while read line; do
stat=$line
# Doing the actual check:
d_tps=`echo $stat | awk '{printf "%f", $2}'`
d_kbread=`echo $stat | awk '{printf "%f", $3}'`
d_kbwritten=`echo $stat | awk '{printf "%f", $4}'`
if [ -n "$d_tps" ]; then
tps=`echo "$d_tps + $tps" | bc | awk '{printf "%f", $0}'`
kbread=`echo "$d_kbread + $kbread" | bc | awk '{printf "%f", $0}'`
kbwritten=`echo "$d_kbwritten + $kbwritten" | bc | awk '{printf "%f", $0}'`
fi
done <<< "$stats"
# Comparing the result and setting the correct level:
if ( [ "`echo "$tps >= $crit_tps" | bc`" == "1" ] || [ "`echo "$kbread >= $crit_read" | bc`" == "1" ] || \
[ "`echo "$kbwritten >= $crit_written" | bc`" == "1" ] ); then
msg="CRITICAL"
status=2
else if ( [ "`echo "$tps >= $warn_tps" | bc`" == "1" ] || [ "`echo "$kbread >= $warn_read" | bc`" == "1" ] || \
[ "`echo "$kbwritten >= $warn_written" | bc`" == "1" ] ); then
msg="WARNING"
status=1
else
msg="OK"
status=0
fi
fi
# Printing the results:
echo "$msg - I/O stats tps=$tps KB_read/s=$kbread KB_written/s=$kbwritten | 'tps'=$tps; 'KB_read/s'=$kbread; 'KB_written/s'=$kbwritten;"
exit $status