In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you about what the three monitoring linux network card traffic scripts are. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.
Script 1:
#! / bin/bash
(ifconfig eth0 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| head-N1)
E0roomoutdated oldstones $(ifconfig eth0 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| tail-N1)
> e0roomtotalroomoldbeans $($e0_in_old + $e0_out_old))
E1roominexpensive $(ifconfig eth2 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| head-N1)
E1roomoutdated oldstones $(ifconfig eth2 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| tail-N1)
E1) (($e1_in_old + $e1_out_old))
While true
Do
Sleep 1
E0recent news $(ifconfig eth0 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| head-N1)
E0overview newwritten $(ifconfig eth0 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| tail-N1)
(($e0_in_new + $e0_out_new))
E1newly published $(ifconfig eth2 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| head-N1)
E1outline newwritten $(ifconfig eth2 | grep bytes | awk'{print $2 "" $6}'| egrep-o'[0-9] +'| tail-N1)
E1 (($e1_in_new + $e1_out_new))
($e0_in_new-$e0_in_old) * 8))
($e0_out_new-$e0_out_old) * 8))
($e0_total_new-$e0_total_old) * 8))
($e1_in_new-$e1_in_old) * 8))
E1subscription outbound $(($e1_out_new-$e1_out_old) * 8)
($e1_total_new-$e1_total_old) * 8))
Echo-e "eth0 IN: $e0_in\ t bplink s OUT: $e0_out\ t bplink s TOTAL: $e0_total\ t bplink s"
Echo-e "eth2 IN: $e1_in\ t bplink s OUT: $e1_out\ t bplink s TOTAL: $e1_total\ t bplink s\ n"
E0_in_old=$e0_in_new
E0_out_old=$e0_out_new
E0_total_old=$e0_total_new
E1_in_old=$e1_in_new
E1_out_old=$e1_out_new
E1_total_old=$e1_total_new
Done
Exit 0
Script 2:
#! / bin/bash
# osdba 2008.10.22 monitor the interface's network traffic.
If [$#-ne 3]; then
Echo Useage: $0 interface interval count
Echo Example: $0 eth0 2 10
Exit
Fi
Eth=$1
Count=$3
Interval=$2
Inbytesfirst=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $2}')
If [- z "$inbytesfirst"]; then
Echo The network interface $eth is not exits!
Exit 1
Fi
Outbytesfirst=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $10}')
Inpacketsfirst=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $3}')
Outpacketsfirst=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $11}')
Sleep $interval "s"
ITunes 0
While ["$I"-lt "$count"]
Do
Inbytesend=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $2}')
Outbytesend=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $10}')
Inpacketsend=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $3}')
Outpacketsend=$ (cat / proc/net/dev | tr':''| awk'/'$eth'/ {print $11}')
Bytesin=$ (($inbytesend-$inbytesfirst))
Bytesout=$ (($outbytesend-$outbytesfirst))
Packetsin=$ (($inpacketsend-$inpacketsfirst))
Packetsout=$ (($outpacketsend-$outpacketsfirst))
If ["$bytesin"-lt "0"]; then
Bytesin=$ ((4294967295-$inbytesfirst+$inbytesend))
# echo bytesin $bytesin $inbytesfirst $inbytesend
Fi
If ["$bytesout"-lt "0"]; then
Bytesout=$ ((4294967295-$outbytesfirst+$outbytesend))
# echo bytesout $bytesout $outbytesfirst $outbytesend
Fi
If ["$packetsin"-lt "0"]; then
Packetsin=$ ((4294967295-$inpacketsfirst+$inpacketsend))
# echo packetsin $packetsin $inpacketsfirst $inpacketsend
Fi
If ["$packetsout"-lt "0"]; then
Packetsout=$ ((4294967295-$outpacketsfirst+$outpacketsend))
# echo packetsout $packetsout $outpacketsfirst $outpacketsend
Fi
Bytesin=$ (($bytesin/$interval))
Bytesout=$ (($bytesout/$interval))
Packetsin=$ (($packetsin/$interval))
Packetsout=$ (($packetsout/$interval))
Sumbytesin=$ (($sumbytesin+$bytesin))
Sumbytesout=$ (($sumbytesout+$bytesout))
Sumpacketsin=$ (($sumpacketsin+$packetsin))
Sumpacketsout=$ (($sumpacketsout+$packetsout))
If [$($I% 20))-eq 0]; then
Echo "ifname | in_kbits/s out_kbits/s | in_kBytes/s out_kBytes/s | in_packets/s out_packets/s"
Echo "- |--"
Fi
Echo $eth $bytesin $bytesout $packetsin $packetsout | awk'{printf ("% 9s | d d | d | d\ n", $1).
Inbytesfirst=$inbytesend
Outbytesfirst=$outbytesend
Inpacketsfirst=$inpacketsend
Outpacketsfirst=$outpacketsend
ITunes $(($item1))
Sleep $interval "s"
Done
Sumbytesin=$ (($sumbytesin/$i))
Sumbytesout=$ (($sumbytesout/$i))
Sumpacketsin=$ (($sumpacketsin/$i))
Sumpacketsout=$ (($sumpacketsout/$i))
Echo "- |--"
Echo Average $sumbytesin $sumbytesout $sumpacketsin $sumpacketsout | awk'{printf ("% 9s | d d | d d | d\ n", $1).
Script 3:
#! / bin/bash
# test network width
Function usage
{
Echo "Usage: $0 million?"
Echo "? e.g. $0 eth0 2"
Exit 65
}
If [$#-lt 2]; then
Usage
Fi
Typeset in in_old dif_in
Typeset out out_old dif_out
Typeset timer
Typeset eth
Eth=$1
Timer=$2
In_old=$ (cat / proc/net/dev | grep $eth | sed-e "s /\ (. *\)\:\ (. *\) /\ 2Unig" | awk'{print $1}')
Out_old=$ (cat / proc/net/dev | grep $eth | sed-e "s /\ (. *\)\:\ (. *\) /\ 2Unig" | awk'{print $9}')
While true
Do
Sleep ${timer}
In=$ (cat / proc/net/dev | grep $eth | sed-e "s /\ (. *\)\:\ (. *\) /\ 2Unig" | awk'{print $1}')
Out=$ (cat / proc/net/dev | grep $eth | sed-e "s /\ (. *\)\:\ (. *\) /\ 2Unig" | awk'{print $9}')
Dif_in=$ (in-in_old) / timer))
Dif_out=$ (out-out_old) / timer))
Echo "IN: ${dif_in} Byte/s OUT: ${dif_out} Byte/s"
In_old=$ {in}
Out_old=$ {out}
Done
Exit 0
These are the three scripts for monitoring linux network card traffic shared by Xiaobian. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.