使用awk统计网卡最大流量及单位换算的问题
使用awk统计网卡最大流量及单位换算的问题,有需要的朋友不妨参考下。
统计出最大的RX和最大的TX,让后相加,流量统计的单位可能不一样,我这里只统计到B、KB、MB和GB,如果流量很到到TB(情况比较少吧...),可以再增加一条即可。
监测数据如下:
16:01:07 RX and TX eth0 2.62305KB/s 0B/s
16:01:12 RX and TX eth0 1.81152KB/s 0B/s
16:01:17 RX and TX eth0 3.33984KB/s 792B/s
16:01:22 RX and TX eth0 3.94238KB/s 1.65625KB/s
16:01:27 RX and TX eth0 3.29688KB/s 1.25977KB/s
16:01:32 RX and TX eth0 3.28711KB/s 848B/s
16:01:37 RX and TX eth0 3.75391KB/s 228B/s
16:07:36 RX and TX eth0 149.52KB/s 3.74805KB/s
实现引功能的牛X脚本,呵呵:
#!/usr/bin/awk -f
{
$6=s($6)
RX = RX > $6 ? RX : $6
$7=s($7)
TX = TX >$7 ? TX : $7
}
function s(tmp)
{
if(tmp ~ /KB/){
sub("KB/s","",tmp)
tmp=tmp*1000 }
else if(tmp ~ /MB/){
sub("MB/s","",tmp)
tmp=tmp*1000*1000}
else if(tmp ~ /GB/){
sub("GB/s","",tmp)
tmp=tmp*1000*1000*1000}
else
sub("B/s","",tmp)
return tmp
}
END{
print RX + TX"B/s"
}
您可能感兴趣的文章:
使用awk统计网卡最大流量及单位换算的问题
怎么让电脑网速提速
统计网卡流量的二个shell脚本(ifconfig)(图文)
计算网卡流量的shell脚本(代码分享)
shell脚本计算Linux网卡流量
ifconfig统计网卡流量的shell脚本
awk单行脚本快速参考
shell脚本采集系统cpu、内存、磁盘、网络信息
找出1小时内占用cpu最多的10个进程的shell脚本
PHP网站大流量与高并发的解决方法