Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1914465
  • 博文数量: 498
  • 博客积分: 2078
  • 博客等级: 大尉
  • 技术积分: 1645
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-18 22:43
个人简介

安大

文章分类

全部博文(498)

文章存档

2017年(1)

2016年(2)

2015年(21)

2014年(90)

2013年(101)

2012年(267)

2011年(16)

分类: LINUX

2013-05-30 14:06:06

原文地址:linux连接数状态统计 作者:exp07

连接数状态获取:netstat在4W以上连接数下工作性能很差。
先看看ss命令:

ss -t -a #统计所有的TCP连接
ss -u -a #统计所有的UDP连接
ss还具有过滤功能,下面列一下常用的功能:
ss state ESTABLISHED #列出所有ESTABLISHED状态的连接
ss -t -a -o excl ESTABLISHED #排除所有ESTABLISHED状态的连接
ss state ESTABLISHED sport eq :80 #列出所有在80端口上状态为ESTABLISHED状态的连接
ss state ESTABLISHED sport eq :80 and not dst 127.0.0.1 #列出所有在80端口上状态为ESTABLISHED状态和目的地址不为127.0.0.1的连接

ss命令来自iproute包。
ss -s会列出一些基本的统计信息:

点击(此处)折叠或打开

  1. #ss -s
  2. Total: 43160 (kernel 43254)
  3. TCP: 43770 (estab 43069, closed 32, orphaned 646, synrecv 0, timewait 24/0), ports 285

  4. Transport Total IP IPv6
  5. * 43254 - -
  6. RAW 0 0 0
  7. UDP 13 10 3
  8. TCP 43738 43535 203
  9. INET 43751 43545 206
  10. FRAG 0 0 0
TCP:?43770?(estab 43069,?closed 32,?orphaned 646,?synrecv 0,?timewait 24/0),?ports 285 这行是什么含义呢,只能去源码里找了:

点击(此处)折叠或打开

  1. ...
  2. printf("TCP: %d (estab %d, closed %d, orphaned %d, synrecv %d, timewait %d/%d), ports %d\n",
  3. s.tcp_total + slabstat.tcp_syns + s.tcp_tws,
  4. sn.tcp_estab,
  5. s.tcp_total - (s.tcp4_hashed+s.tcp6_hashed-s.tcp_tws),
  6. s.tcp_orphans,
  7. slabstat.tcp_syns,
  8. s.tcp_tws, slabstat.tcp_tws,
  9. slabstat.tcp_ports
  10. );


仔细核对了下,estab和传统的ESTABLISHED统计结果一致,其他几个字段均对不上号,尤其这里的synrecv也不是SYN_RECV的统计,来自slabstat统计。
这条路不能完美的满足我的需求,待续

ss -tn state CLOSE-WAIT
阅读(4835) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~