File: //lib64/nagios/plugins/check_a2_packets.mvps
#!/bin/bash
# Ref - SYSENG-26866 - Alert if packets per second crosses 30k/s
#
_packet_per_sec_collect() {
_packets_warn=20000
_packets_crit=30000
_packets_last_file="/tmp/packets_incoming_count"
# first create a file to save first value
if [ ! -f "${_packets_last_file}" ]; then
grep -Ev 'lo:' /proc/net/dev | tail -1 | awk '{print $3}' > ${_packets_last_file}
exit
else
# find delta packet value and calculate by seconds
# alert or warn as needed
_packets_last_file_age=$(stat -c %Y -- ${_packets_last_file})
_packets_dt_current=$(date +%s)
_packets_last_file_age_seconds=$(( _packets_dt_current - _packets_last_file_age ))
_packets_last=$(cat ${_packets_last_file})
_packets_current=$(grep -Ev 'lo:' /proc/net/dev | tail -1 | awk '{print $3}')
if [ "${_packets_current}" -gt "${_packets_last}" ] && [ "${_packets_last_file_age_seconds}" -gt 1 ]; then
_packets_delta_f=$(( _packets_current - _packets_last ))
_packets_delta=$(( _packets_delta_f / _packets_last_file_age_seconds ))
fi
if [ -n "${_packets_delta}" ]; then
if [ "${_packets_delta}" -gt "${_packets_warn}" ] && [ "${_packets_delta}" -lt "${_packets_crit}" ]; then
echo "$(hostname) has ${_packets_delta} received packets per second"
exit 1
elif [ "${_packets_delta}" -gt "${_packets_crit}" ]; then
echo "$(hostname) has ${_packets_delta} received packets per second"
exit 2
else
echo "$(hostname) has ${_packets_delta} received packets per second"
exit 0
fi
else
echo "$(hostname) has 0 received packets per second"
exit 0
fi
fi
grep -Ev 'lo:' /proc/net/dev | tail -1 | awk '{print $3}' > ${_packets_last_file}
}
_packet_per_sec_collect