同事想获取iftop最后一行rates值的内容,于是搜索到的
http://www.jbxue.com/LINUXjishu/29854.html
sed 可以用 $ 来指定最后一行:
1
|
sed -n -e '$p' xxx |
-n 的意思是不用每行都输出。
$p 的意思是打印最后一行。
xxx 是那个文件的名字。
另外用
1
|
tail -n 1 xxx |
也是一种办法。tail 本来就是用来打印一个文件的最后几行的。-n 1 告诉它只打印一行。
I used What i can use to track very specific and accurate real-time network statistics? |
|||
add a comment
|
Your application is probably sending packets to a specific UDP or TCP port number or to a specific IP-address. You can therefore use something like TCPdump to capture that traffic. TCPdump doesn't give you the real-time stats you desire but you can feed it's output to something that does (I'll try to update this answer with an answer later). Update:
I interrupted that after a minute by pressing Ctrl+C. You'd need to add a suitable filter expression at the end of the The program
It's just an example, adjust to taste. |
|||||||||||||
|
Usage as below from same folder: To check packer per interface: To check speed per interface: Measure Packets per Second on an Interface netpps.sh as file name
Measure Network Bandwidth on an Interface netspeed.sh as file name
Please refer this site for more info http://xmodulo.com/measure-packets-per-second-throughput-high-speed-network-interface.html |
|||
Easiest to use and easiest to control output and redirect to file for continuous logging:
Probably comes with most linux distributions, and can be installed with brew on mac |
|||
I think you can use the proc interface to get the information you need. I created this little shell script called rt_traf.sh:
This will print the in and out octets separated by a tab. Octets multiplied by 8 will give you bits/second and then divided by 10^6 will give you megabits/second. Of course you can add this to the shell script to format the output how you want it. You can call this with the PID of your application like so
The
Again the math can be adjusted for the size/times you need. Not the most elegant or shrink wrapped solution but it should work in a pinch. |
|||||
|