# 原始接口
vppctl show interface
[root@localhost]# vppctl show int | head -50
Name Idx State MTU (L3/IP4/IP6/MPLS) Counter Count
GigabitEthernet0/1/0 1 up 9000/0/0/0 rx packets 6967165921
rx bytes 1644497622028
tx packets 1903533769
tx bytes 1104461789304
drops 4967450326
punt 827
ip4 5792194126
ip6 794995
GigabitEthernet0/2/0 2 up 1500/0/0/0 rx packets 1149531371
rx bytes 306747840023
tx packets 1239097315
tx bytes 562813141612
drops 5928014
punt 133
ip4 1140993136
ip6 4318724
loop2069 83 up 1500/0/0/0
loop2074 56 up 1500/0/0/0 rx packets 8445860
rx bytes 4145051242
tx packets 16761142
tx bytes 9944192500
drops 1846
ip4 8445860
loop2076 238 up 1500/0/0/0 rx packets 10019246
rx bytes 2008224726
tx packets 20901012
tx bytes 4348662360
drops 29352
ip4 9994296
loop2084 93 up 1500/0/0/0 rx packets 7032297
rx bytes 737839794
tx packets 15744138
tx bytes 1642388506
drops 39843
ip4 7004127
loop2085 11 up 1500/0/0/0 rx packets 611863
rx bytes 476803649
tx packets 1223724
tx bytes 970716106
drops 653
ip4 609829
# 计算吞吐率的方法
两次调用计算rx packets 增长值,并除以时间间隔:
{ printf "\033[7m$(date +%T)/%-22s%13s %18s %10s\033[m\n" $(strings /bin/vpp|awk '/built.by/{gsub(/\./,"",$2);print substr($2,1,7)}') rxKpps/pktlen txKpps/pktlen dx_pps >&2
vppctl show int; sleep 2; vppctl show interface; } | sed -r 's/^([^ ])/\n\1/;s/\r//g' | awk 'BEGIN{RS="";u=2002;}/packet/{
drop=tx_packets=tx_bytes=0;rx_packets=$7;rx_bytes=$10;if($11=="tx"){tx_packets=$13;tx_bytes=$16};if($17=="drops"){drop=$18}
rx=rx_packets-arr[$1,1];r=rx_bytes-arr[$1,2];tx=tx_packets-arr[$1,3];t=tx_bytes-arr[$1,4];px=drop-arr[$1,5]
if(arr[$1]==$1){printf "%-24s%13.3f %-4d %13.3f %-4d%10u\n",arr[$1],rx/u,r/(rx+0.0001),tx/u,t/(tx+0.0001),px}
arr[$1,1]=rx_packets;arr[$1,2]=rx_bytes;arr[$1,3]=tx_packets;arr[$1,4]=tx_bytes;arr[$1,5]=drop;arr[$1]=$1;fflush(stdout)
}' | sort -rnk2
输出效果: