Skip to content

Commit

Permalink
[dropcheck]: Add the dropcheck as a script to sum up drop counters in…
Browse files Browse the repository at this point in the history
… a duration (sonic-net#62)

- This tool could be used in monit to check periodically and exit 1
  when the drop exceeds certain threshold for monit to alert in syslog.
  • Loading branch information
Shuotian Cheng authored Jun 15, 2017
1 parent e604cea commit 3cc779f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/dropcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

#
# Usage: dropcheck [-p PERIOD] [-t THRESHOLD]
# -p: Set the period of time for portstat to get all counters
# -t: Set the threshold to exit 1
#

PERIOD=3
THRESHOLD=100

while getopts ":p:t:" opt; do
case $opt in
p)
PERIOD=$OPTARG
;;
t)
THRESHOLD=$OPTARG
;;
/?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
esac
done

# Sum up column RX_DRP and TX_DRP for all ports
TOTAL_DROP=`portstat -p $PERIOD | awk -F' ' '{if (NR>3) {s+=$9+$16}} END {print s}'`
echo "Total number of drop packets during the last $PERIOD seconds is $TOTAL_DROP!"

# Exit 1 for monit to check the output of the script
if [ $TOTAL_DROP -gt $THRESHOLD ]; then
exit 1
fi
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
'scripts/boot_part',
'scripts/coredump-compress',
'scripts/decode-syseeprom',
'scripts/dropcheck',
'scripts/fast-reboot',
'scripts/fast-reboot-dump.py',
'scripts/generate_dump',
Expand Down

0 comments on commit 3cc779f

Please sign in to comment.