2019-07-23 22:28:09 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2021-08-29 15:27:33 +02:00
|
|
|
EXCLUDE_REGEXP='(lo|bond|vmbr)'
|
2019-07-23 22:28:09 +02:00
|
|
|
|
2021-08-29 15:27:33 +02:00
|
|
|
#
|
|
|
|
# Help function
|
|
|
|
#
|
|
|
|
usage() {
|
|
|
|
cat <<EOF
|
|
|
|
This script simply outputs the number of packets and volume of data
|
|
|
|
emitted and received by network devices. Its status is always 0/OK.
|
|
|
|
|
|
|
|
Usage :
|
|
|
|
$0 [-e egrep_exclude_pattern]
|
|
|
|
|
|
|
|
Example :
|
|
|
|
$0 -e '(lo|^br-|^veth)'
|
|
|
|
|
|
|
|
Default values:
|
|
|
|
egrep_exclude_pattern: $EXCLUDE_REGEXP
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
#
|
|
|
|
# Loop on parameters + tests
|
|
|
|
#
|
|
|
|
while getopts he: f; do
|
|
|
|
case "$f" in
|
|
|
|
'h')
|
|
|
|
usage
|
|
|
|
exit
|
|
|
|
;;
|
|
|
|
|
|
|
|
'e')
|
|
|
|
EXCLUDE_REGEXP="$OPTARG"
|
|
|
|
;;
|
|
|
|
|
|
|
|
\?)
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
|
|
# We don't bother buffering, let's output as we go
|
2019-07-23 22:28:09 +02:00
|
|
|
printf "OK |"
|
|
|
|
|
2021-08-29 15:27:33 +02:00
|
|
|
# Loop on each device
|
|
|
|
for i in $( cat /proc/net/dev | sed -n 's/^[[:space:]]*\([a-z0-9\.\-]\+\):.*/\1/p' | sort ); do
|
|
|
|
if [ $( echo "$i" | egrep -c -e "$EXCLUDE_REGEXP" ) -gt 0 ]; then
|
2019-07-23 22:28:09 +02:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
VOLUME_RECU="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 1 )"
|
|
|
|
VOLUME_EMIS="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 9 )"
|
|
|
|
PAQUETS_RECUS="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 2 )"
|
|
|
|
PAQUETS_EMIS="$( cat /proc/net/dev | sed -n "s/^[[:space:]]*$i:[[:space:]]*//p" | sed 's/[[:space:]]\+/ /g' | cut -d " " -f 10 )"
|
|
|
|
printf " %s_packets_in=%d %s_packets_out=%d %s_volume_in=%d %s_volume_out=%d" "$i" "$PAQUETS_RECUS" "$i" "$PAQUETS_EMIS" "$i" "$VOLUME_RECU" "$i" "$VOLUME_EMIS"
|
|
|
|
done
|
|
|
|
|
|
|
|
printf "\n"
|