The traffic of the database server, image server, FTP server, and other NICS is usually relatively large. Therefore, we need to perform necessary monitoring measures to determine whether the NIC will become a bottleneck, you can also set up a network card traffic baseline to check whether the traffic is abnormal.
You can use shell scripts to write a small piece of code to view the NIC port traffic:
1) view the traffic of a specified Nic Port
2) Check the inbound/outbound value/Total value of the port;
3) Specify the interval and number of observations for the second port traffic observation;
Three effects of the shell script network_top.sh are as follows ,:
1) The network_top.sh script is executed without passing any parameter error message.
Figure1-1
2) run the network_top.sh script to pass the error message of the error parameter.
Figure1-2
3) execute the network_top.sh script to pass the collected data of the parameters correctly.
Figure1-3
Code segment of the shell script network_top.sh
#!/bin/bash#Name: network_top.sh#Usage: sh network_top.sh --network-port=eth0 --interval-time=1 --repeat-total=10#Description: monitor the network interface's flow#WebSite: www.mysqlops.comusage(){cat <<EOFUsage: $0 [OPTIONS] --network-port=ethN Show which network port,For Example --network-port=eth0. --interval-time=N Every twice that need interval time,For Example --interval-time=1. --repeat-total=N We need to see a continuous flow of card number,For Example --repeat-total=10.EOFexit 1}if [ "$#" -lt 1 ] ; then usagefifor INPUT_DATA in $*do INPUT_DATA_1=$1 Val=`echo "$INPUT_DATA_1" | sed -e "s;--[^=]*=;;"` case "$INPUT_DATA_1" in --network-port=*) ETH_PORT="$Val" ;; --interval-time=*) INTERVAL_TIME="$Val" ;; --repeat-total=*) REPEAT_TOTAL="$Val" ;; *) echo -e "\n ERROR VARIABLES: $INPUT_DATA_1 \n" usage exit 1 ;; esac shiftdoneinfirst=$(cat /proc/net/dev |tr ':' ' '|awk '/'$ETH_PORT'/{print $2}')outfirst=$(cat /proc/net/dev |tr ':' ' '|awk '/'$ETH_PORT'/{print $10}')echo "$ETH_PORT" "in_bytes/sec" "out_bytes/sec" "total_bytes/sec" |awk '{printf("%10s %16s %16s %16s\n",$1,$2,$3,$4)}'sleep $INTERVAL_TIME"s"i=0while [ "$i" -lt "$REPEAT_TOTAL" ]do inend=$(cat /proc/net/dev |tr ':' ' '|awk '/'$ETH_PORT'/{print $2}') outend=$(cat /proc/net/dev |tr ':' ' '|awk '/'$ETH_PORT'/{print $10}') sumin=$((($inend-$infirst)/$INTERVAL_TIME)) sumout=$((($outend-$outfirst)/$INTERVAL_TIME)) sum=$(($sumin+$sumout)) echo "$ETH_PORT" $sumin $sumout $sum |awk '{printf("%10s %16s %16s %16s\n",$1,$2,$3,$4)}' infirst=$inend outfirst=$outend i=$(($i+1)) sleep $INTERVAL_TIME"s"done