linux下tcp状态是从哪查出来的
2016-04-20 15:12
387 查看
linux中,各种tcp连接的状态存储在 /proc/net/tcp 文件中
其中st列就是tcp的各种状态,那么这个值代表什么意思呢? 有网友从内核源码里找到了这个
那么各种状态对应的数字就清楚了。
我们以dstat工具为例,看看它是怎么统计的各种tcp状态的数量的。
从程序中看到,dstat将11种tcp状态分了5类做了下合并显示出来.
其中st列就是tcp的各种状态,那么这个值代表什么意思呢? 有网友从内核源码里找到了这个
enum { TCP_ESTABLISHED = 1, TCP_SYN_SENT, TCP_SYN_RECV, TCP_FIN_WAIT1, TCP_FIN_WAIT2, TCP_TIME_WAIT, TCP_CLOSE, TCP_CLOSE_WAIT, TCP_LAST_ACK, TCP_LISTEN, TCP_CLOSING, /* Now a valid state */ TCP_MAX_STATES /* Leave at the end! */ };
那么各种状态对应的数字就清楚了。
我们以dstat工具为例,看看它是怎么统计的各种tcp状态的数量的。
class dstat_tcp(dstat): def __init__(self): self.name = 'tcp sockets' self.nick = ('lis', 'act', 'syn', 'tim', 'clo') self.vars = ('listen', 'established', 'syn', 'wait', 'close') self.type = 'd' self.width = 4 self.scale = 100 self.open('/proc/net/tcp', '/proc/net/tcp6') def extract(self): for name in self.vars: self.val[name] = 0 for l in self.splitlines(): if len(l) < 12: continue ### 01: established, 02: syn_sent, 03: syn_recv, 04: fin_wait1, ### 05: fin_wait2, 06: time_wait, 07: close, 08: close_wait, ### 09: last_ack, 0A: listen, 0B: closing if l[3] in ('0A',): self.val['listen'] += 1 elif l[3] in ('01',): self.val['established'] += 1 elif l[3] in ('02', '03', '09',): self.val['syn'] += 1 elif l[3] in ('06',): self.val['wait'] += 1 elif l[3] in ('04', '05', '07', '08', '0B',): self.val['close'] += 1
从程序中看到,dstat将11种tcp状态分了5类做了下合并显示出来.
相关文章推荐
- linux_group简单
- VirtualBox虚拟机Linux CentOS 7连外网小记
- 保护你的Web服务器 iptables防火墙脚本全解读
- linux下tar等打包压缩工具及while语句编写脚本(九)
- centos mysql安装 完全版
- Linux常用命令
- linux常用脚本
- 查看Linux下系统资源占用常用命令(top、free、uptime)
- Linux系统下-进程间通信(共享内存-详解)
- 关于linux下wireshark启动时Lua报错
- 如何将Linux rm命令删除的文件放入垃圾箱
- Linux下部署weblogic应用
- linux中date -s 和虚拟机的时间
- linux驱动中使用顺序锁
- CentOS vncserver配置
- linux压缩和解压缩命令
- linux 中的time命令
- linux驱动中实现上层select接口
- Linux中变量#,#,@,0,0,1,2,2,*,$$,$?的含义
- linux系统中设置静态ip地址