ss与netstat效率对比。ss更快些,且netstat在并发高于2万情况下会有严重的卡顿现象
[[email protected] zabbix]#time ss state all|awk ‘{++S[$1]} END {for (a in S) {printf "%11-s %s\n",a,S[a]}}‘ #不是LL,是2个1
ESTAB 1
State 1
TIME-WAIT 5
LISTEN 13
real 0m0.005s
user 0m0.002s
sys 0m0.002s
[[email protected] zabbix]# time netstat -an|awk ‘/^tcp/ {++s[$NF]} END {for ( a in s ) {printf "%11-s %s\n",a,s[a]}}‘ #不是LL,是2个1
TIME_WAIT 9
ESTABLISHED 1
LISTEN 13
real 0m0.008s
user 0m0.002s
sys 0m0.004s
监控tcp连接状态可查看/proc/net/tcp文件
[[email protected] zabbix]# tail -3 /proc/net/tcp #第4列绿色为tcp的各种状态
5: 00000000:CE74 00000000:0000 0A 00000000:00000000 00:00000000 00000000 29 0 10581 1 ffff880036b42040 99 0 0 10 -1
6: 5100000A:8F4C 07AC2A79:0050 06 00000000:00000000 03:00000FA1 00000000 0 0 0 3 ffff88001de8aec0
7: 5100000A:0016 0100000A:D7D0 01 00000040:00000000 01:00000018 00000000 0 0 185660 4 ffff8800185bf180 24 3 21 6 4