forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dropcheck]: Add the dropcheck as a script to sum up drop counters in…
… 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
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters