default network interface monitoring (#821)

* default network interface monitoring 

I added the function NetworkMonitorMode(). One could argue that the MonitorMode() function should own these stats, but I think it would make things a bit too busy-ish. Having said that, I'm not married to accessing network stats through an independent function.
regards..../j

* Update armbianmonitor

* Update armbianmonitor

* Update armbianmonitor

* Update armbianmonitor

* Update armbianmonitor
This commit is contained in:
jaskcon 2017-11-12 15:30:57 -05:00 committed by Thomas Kaiser
parent d98c960ed5
commit 35247cc040

View file

@ -120,7 +120,7 @@ Main() {
} # Main
ParseOptions() {
while getopts 'hHbBuUrRmMd:Dc:C:pPv' c ; do
while getopts 'hHbBuUrRmMnNd:Dc:C:pPv' c ; do
case ${c} in
H)
# display full help test
@ -139,6 +139,12 @@ ParseOptions() {
MonitorMode ${OPTARG}
exit 0
;;
n|N)
# network monitoring mode
rf1=$2
NetworkMonitorMode ${OPTARG}
exit 0
;;
u|U)
# Upload /var/log/armhwinfo.log to be of help in support forum.
fping sprunge.us 2>/dev/null | grep -q alive || \
@ -239,6 +245,8 @@ DisplayUsage() {
echo -e " armbianmonitor ${BOLD}-D${NC} tries to upload debug disk info to improve armbianmonitor"
echo -e " armbianmonitor ${BOLD}-m${NC} provides simple CLI monitoring - scrolling output"
echo -e " armbianmonitor ${BOLD}-M${NC} provides simple CLI monitoring - fixed-line output"
echo -e " armbianmonitor ${BOLD}-n${NC} provides simple CLI network monitoring - scrolling output"
echo -e " armbianmonitor ${BOLD}-N${NC} provides simple CLI network monitoring - fixed-line output"
echo -e " armbianmonitor ${BOLD}-p${NC} tries to install cpuminer for performance measurements"
echo -e " armbianmonitor ${BOLD}-r${NC} tries to install RPi-Monitor"
echo -e " armbianmonitor ${BOLD}-u${NC} tries to upload armhwinfo.log for support purposes"
@ -959,4 +967,107 @@ VerifyInstallation() {
fi
} # VerifyInstallation
NetworkMonitorMode() {
# Allow armbianmonitor to return back to armbian-config
trap "exit 0" 0 1 2 3 15
timerStart
kickAllStatsDown
iface=$(route -n | egrep UG | egrep -o "[a-zA-Z0-9]*$")
printf "\nruntime network statistics: $(uname -n)\n"
printf "[tap 'd' to display column headings]\n"
printf "[tap 'z' to reset counters]\n"
printf "[use <ctrl-c> to exit]\n"
printf "[bps: bits/s, Mbps: megabits/s, pps: packets/s, MB: megabytes]\n\n"
printf "%-11s %-66s %-66s\n" $(echo -en "$iface rx.stats____________________________________________________________ tx.stats____________________________________________________________")
printf "%-11s %-11s %-11s \u01B0.%-11s %-11s \u01B0.%-11s \u01A9.%-11s %-11s %-11s \u01B0.%-11s %-11s \u01B0.%-11s \u01A9.%-11s\n\n" $(echo -en "count bps Mbps Mbps pps pps MB bps Mbps Mbps pps pps MB")
while true; do
nss=(`sed -n 's/'$iface':\s//p' /proc/net/dev`)
rxB=${nss[0]}
rxP=${nss[1]}
txB=${nss[8]}
txP=${nss[9]}
drxB=$(( ${rxB} - ${prxB} ))
drxb=$(( ${drxB}* 8 ))
drxmb=$(echo "scale=2;$drxb/1000000"|bc)
drxP=$(( ${rxP} - ${prxP} ))
dtxB=$(( ${txB} - ${ptxB} ))
dtxb=$(( ${dtxB}* 8 ))
dtxmb=$(echo "scale=2;$dtxb/1000000"|bc)
dtxP=$(( ${txP} - ${ptxP} ))
if [ "$cnt" != "0" ]; then
if [ "$c" == "N" ]; then
printf "\x1b[1A"
fi
srxb=$(( ${srxb} + ${drxb} ))
stxb=$(( ${stxb} + ${dtxb} ))
srxB=$(( ${srxB} + ${drxB} ))
stxB=$(( ${stxB} + ${dtxB} ))
srxP=$(( ${srxP} + ${drxP} ))
stxP=$(( ${stxP} + ${dtxP} ))
srxMB=$(echo "scale=2;$srxB/1024^2"|bc)
stxMB=$(echo "scale=2;$stxB/1024^2"|bc)
arxb=$(echo "scale=2;$srxb/$cnt"|bc)
atxb=$(echo "scale=2;$stxb/$cnt"|bc)
arxmb=$(echo "scale=2;$arxb/1000000"|bc)
atxmb=$(echo "scale=2;$atxb/1000000"|bc)
arxP=$(echo "scale=0;$srxP/$cnt"|bc)
atxP=$(echo "scale=0;$stxP/$cnt"|bc)
printf "%-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s %-11s\n" $(echo -en "$cnt $drxb $drxmb $arxmb $drxP $arxP $srxMB $dtxb $dtxmb $atxmb $dtxP $atxP $stxMB")
fi
prxB="$rxB"
prxP="$rxP"
ptxB="$txB"
ptxP="$txP"
let cnt++
timerShut
read -n1 -s -t$procSecs zeroAll
timerStart
if [ "$zeroAll" == 'z' ]; then
kickAllStatsDown
fi
if [ "$zeroAll" == 'd' ]; then
scrollingHeader
fi
done
}
scrollingHeader() {
printf "%-11s %-66s %-66s\n" $(echo -en "$iface rx.stats____________________________________________________________ tx.stats____________________________________________________________")
printf "%-11s %-11s %-11s \u01B0.%-11s %-11s \u01B0.%-11s \u01A9.%-11s %-11s %-11s \u01B0.%-11s %-11s \u01B0.%-11s \u01A9.%-11s\n\n" $(echo -en "count bps Mbps Mbps pps pps MB bps Mbps Mbps pps pps MB")
}
timerStart() {
read st0 st1 < <(date +'%s %N')
}
timerShut() {
read sh0 sh1 < <(date +'%s %N')
jusquaQuand=$(echo "scale=2;($sh0-$st0)*1000000000+($sh1-$st1)"|bc)
procSecs=$(echo "scale=2;(1000000000-$jusquaQuand)/1000000000"|bc)
if [ "$rf1" == "debug" ]; then
printf "time controller adjustment: $procSecs\n"
if [ "$c" == "N" ]; then
printf "\x1b[1A"
fi
fi
}
kickAllStatsDown() {
prxB=0
prxP=0
ptxB=0
ptxP=0
srxb=0
stxb=0
srxB=0
stxB=0
srxMB=0
stxMB=0
srxP=0
stxP=0
cnt=0
}
Main "$@"