| 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
file="/var/spool/icinga2/iostat_data.txt"
lockfile="/tmp/iostat_check.lock"
partition="$1"
warning="$2"
critical="$3"
MAX_WAIT=60
start_iostat_collection() {
touch "$lockfile"
setsid bash -c "
stdbuf -oL iostat -d 1 50 -k \
| awk -v part='^$partition' '\$0 ~ part { if (++count > 1) print }' \
>> '$file'
rm -f '$lockfile'
" >/dev/null 2>&1 &
}
# Validate inputs
if [[ -z "$partition" || -z "$warning" || -z "$critical" ]]; then
echo "UNKNOWN - Missing arguments. Usage: $0 <partition> <warning_kB/s> <critical_kB/s>"
exit 3
fi
# Acquire fcntl-style lock using flock
exec 200>"$lockfile"
flock -w $MAX_WAIT 200
if [ $? -ne 0 ]; then
echo "UNKNOWN - Could not acquire lock on $lockfile after $MAX_WAIT seconds."
exit 3
fi
# If the data file doesn't exist, this is the first run (e.g. after reboot)
if [ ! -f "$file" ] || { [ ! -s "$file" ] && ! pgrep -f "/usr/bin/iostat" > /dev/null; }; then
touch "$file"
start_iostat_collection
echo "UNKNOWN - Initial iostat data collection in progress. Please wait for the next check."
exit 3
fi
# If the file is still empty, wait until we have usable data
if [ ! -s "$file" ]; then
echo "UNKNOWN - No iostat data available yet. Waiting for data to populate."
exit 3
fi
# Compute averages using awk
read avg_tps avg_read avg_written <<< $(awk '
{
tps += $2;
read += $3;
wrtn += $4;
count++;
}
END {
if (count > 0)
printf "%.2f %.2f %.2f", tps / count, read / count, wrtn / count;
else
print "0 0 0"
}' "$file")
PerfData="tps=${avg_tps};;;; KB_read/s=${avg_read};;;; KB_written/s=${avg_written};;;;"
status=0
ret_type="OK"
# Determine status based on thresholds
if (( $(echo "$avg_read >= $critical" | bc -l) )); then
ret_type="CRITICAL"
status=2
elif (( $(echo "$avg_read >= $warning" | bc -l) )); then
ret_type="WARNING"
status=1
fi
echo "$ret_type - Average I/O: tps=${avg_tps}, read=${avg_read}kB/s, written=${avg_written}kB/s | $PerfData"
# Reset data for next run
cat /dev/null > "$file"
start_iostat_collection
exit $status