ss is one another utility to investigate sockets(特适合大规模tcp链接)

原创文章,转载请注明: 转载自系统技术非业余研究

本文链接地址: ss is one another utility to investigate sockets(特适合大规模tcp链接)

具体的可以参考这里

他的最大特点是快, 当你的系统有上万个tcp链接要了解的时候的时候, 你就知道我说什么了. netstat等常规工具变成废铁了, 这时候他的作用就非常明显了.

/proc interface is inadequate, unfortunately. When amount of sockets is enough large, netstat or even plain cat /proc/net/tcp/ cause nothing but pains and curses. In linux-2.4 the desease became worse: even if amount of sockets is small reading /proc/net/tcp/ is slow enough.

This utility presents a new approach, which is supposed to scale well. I am not going to describe technical details here and will concentrate on description of the command. The only important thing to say is that it is not so bad idea to load module tcp_diag, which can be found in directory Modules of iproute2. If you do not make this ss will work, but it falls back to /proc and becomes slow like netstat, well, a bit faster yet (see section “Some numbers”).

从技术上讲, 它主要是通过/proc来获取各种各样的统计信息. 特别是当处理tcp的时候用到了, tcp_diag功能. tcp_diag是tcp协议栈用于诊断和统计的一个模块, 用netfilter来获取第一手的信息的.  ss就用到了这个技术, 保证了信息的快捷获取.

这个软件是隶属于iproute包的,  如果你的系统没有的话可以这样安装:

apt-get  -y install iproute

用它可以了解下协议栈占用的内存, 每个链接的队列使用情况, 每个链接属于哪个进程.
而之前唯一能用的就是:

watch -n  1 ‘cat /proc/net/sockstat‘

下面简单介绍下他的使用:

[email protected]:/usr/src/iproute-20090324/misc# ss --help
Usage: ss [ OPTIONS ]
ss [ OPTIONS ] [ FILTER ]
-h, --help           this message
-V, --version        output version information
-n, --numeric        don‘t resolve service names
-r, --resolve       resolve host names
-a, --all            display all sockets
-l, --listening      display listening sockets
-o, --options       show timer information
-e, --extended      show detailed socket information
-m, --memory        show socket memory usage
-p, --processes      show process using socket
-i, --info           show internal TCP information
-s, --summary        show socket usage summary
 
-4, --ipv4          display only IP version 4 sockets
-6, --ipv6          display only IP version 6 sockets
-0, --packet display PACKET sockets
-t, --tcp            display only TCP sockets
-u, --udp            display only UDP sockets
-d, --dccp           display only DCCP sockets
-w, --raw            display only RAW sockets
-x, --unix           display only Unix domain sockets
-f, --family=FAMILY display sockets of type FAMILY
 
-A, --query=QUERY
QUERY := {all|inet|tcp|udp|raw|unix|packet|netlink}[,QUERY]
 
-F, --filter=FILE   read filter information from FILE
FILTER := [ state TCP-STATE ] [ EXPRESSION ]
[email protected]:/usr/src/iproute-20090324/misc# ss -s
Total: 750 (kernel 761)
TCP:   21 (estab 7, closed 0, orphaned 0, synrecv 0, timewait 0/0), ports 0
 
Transport Total     IP        IPv6
*         761       -         -
RAW       0         0         0
UDP       3         3         0
TCP       21        18        3
INET      24        21        3
FRAG      0         0         0
[email protected]:/usr/src/iproute-20090324/misc# ss -t -m
State      
Recv-Q
Send-Q                                                                    
Local
Address:Port                                                                        
Peer Address:Port
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4251
mem:(r0,w0,f4096,t0)
CLOSE-WAIT 
38    
0

192.168.235.147:13910                                                                       
174.36.30.67:https

mem:(r672,w0,f3424,t0)
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4635
mem:(r0,w0,f4096,t0)
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:54620

mem:(r0,w0,f0,t0)
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:1095
mem:(r0,w0,f4096,t0)
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:44234

mem:(r0,w0,f0,t0)
ESTAB      
0     
0

127.0.0.1:54620                                                                          
127.0.0.1:4369

mem:(r0,w0,f0,t0)
ESTAB      
0     
0

127.0.0.1:44234                                                                          
127.0.0.1:4369

mem:(r0,w0,f0,t0)
[email protected]:/usr/src/iproute-20090324/misc# ss -p
State      
Recv-Q
Send-Q                                                                    
Local
Address:Port                                                                        
Peer Address:Port
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4251     users:(("sshd",8373,3))
CLOSE-WAIT 
38    
0

192.168.235.147:13910                                                                       
174.36.30.67:https   
users:(("dropbox",2674,13))

ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4635     users:(("sshd",350,3))
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:54620   
users:(("epmd",28338,5))

ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:1095     users:(("sshd",29044,3))
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:44234   
users:(("epmd",28338,4))

ESTAB      
0     
0

127.0.0.1:54620                                                                          
127.0.0.1:4369    
users:(("beam.smp",25947,11))

ESTAB      
0     
0

127.0.0.1:44234                                                                          
127.0.0.1:4369    
users:(("inet_gethost",23783,8),("inet_gethost",23784,8))

[email protected]:/usr/src/iproute-20090324/misc# ss -i
State      
Recv-Q
Send-Q                                                                    
Local
Address:Port                                                                        
Peer Address:Port
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4251
cubic rto:396 rtt:124.5/66 ato:40 cwnd:4 send 375.3Kbps rcv_rtt:296456 rcv_space:66472
CLOSE-WAIT 
38    
0

192.168.235.147:13910                                                                       
174.36.30.67:https

cubic wscale:7,9 rto:612 rtt:256/52 ato:40 cwnd:5 send 213.8Kbps rcv_rtt:259 rcv_space:5840
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4635
cubic rto:356 rtt:144/33 ato:40 cwnd:4 send 324.4Kbps rcv_rtt:511258 rcv_space:46760
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:54620

cubic wscale:9,9 rto:204 rtt:4/2 ato:40 cwnd:3 send 98.3Mbps rcv_space:32768
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:1095
cubic rto:232 rtt:21/18 ato:40 cwnd:5 ssthresh:4 send 2.8Mbps rcv_rtt:173516 rcv_space:118904
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:44234

cubic wscale:9,9 rto:204 rtt:4/2 ato:40 cwnd:3 send 98.3Mbps rcv_space:32768
ESTAB      
0     
0

127.0.0.1:54620                                                                          
127.0.0.1:4369

cubic wscale:9,9 rto:204 rtt:4/2 ato:40 cwnd:3 send 98.3Mbps rcv_space:32792
ESTAB      
0     
0

127.0.0.1:44234                                                                          
127.0.0.1:4369

cubic wscale:9,9 rto:204 rtt:4/2 ato:40 cwnd:3 send 98.3Mbps rcv_space:32792
[email protected]:/usr/src/iproute-20090324/misc# ss -e
State      
Recv-Q
Send-Q                                                                    
Local
Address:Port                                                                        
Peer Address:Port
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4251     timer:(keepalive,50min,0) ino:1843366 sk:c2ea2600
CLOSE-WAIT 
38    
0

192.168.235.147:13910                                                                       
174.36.30.67:https    ino:12200 sk:c2ea2140

ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4635     timer:(keepalive,2min59sec,0) ino:1101514 sk:c2ea4740
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:54620    ino:2309430 sk:c2ea2ac0

ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:1095     timer:(keepalive,6min59sec,0) ino:379842 sk:c2f4af80
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:44234    ino:2044745 sk:c2ea3440

ESTAB      
0     
0

127.0.0.1:54620                                                                          
127.0.0.1:4369     ino:2309429 sk:c2ea7200

ESTAB      
0     
0

127.0.0.1:44234                                                                          
127.0.0.1:4369     ino:2044744 sk:c2ea1300

[email protected]:/usr/src/iproute-20090324/misc# ss -o
State      
Recv-Q
Send-Q                                                                    
Local
Address:Port                                                                        
Peer Address:Port
ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4251     timer:(keepalive,50min,0)
CLOSE-WAIT 
38    
0

192.168.235.147:13910                                                                       
174.36.30.67:https

ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:4635     timer:(keepalive,2min50sec,0)
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:54620

ESTAB       0      0                                                                        192.168.235.147:ssh                                                                       192.168.235.155:1095     timer:(keepalive,6min50sec,0)
ESTAB      
0     
0

127.0.0.1:4369                                                                           
127.0.0.1:44234

ESTAB      
0     
0

127.0.0.1:54620                                                                          
127.0.0.1:4369

ESTAB      
0     
0

127.0.0.1:44234                                                                          
127.0.0.1:4369

Have fun!!!

时间: 2024-10-05 23:55:25

ss is one another utility to investigate sockets(特适合大规模tcp链接)的相关文章

#20 ifconfig、route、netstat、ip、ss命令详解与修改主机名与网卡配置文件

网络的结构: 硬件:计算机.互联设备.网络设备 软件:操作系统.协议.应用程序.数据库 网络的功能: 资源共享:目的 数据通信:手段 网络通信模型 ISO/OSI: 应用层 表示层 会话层 传输层 网络层 数据链路层 为物理层 TCP/IP: 应用层 传输层 互联网层 网络访问层 数据报文封装格式: 对等通信: 应用层:数据流进程封装: 传输层:数据段(TCP segment)或数据报(UDP data-prog): 最大的报文不能超过65535字节: 互联网层:数据包或IP数据报(ip pac

Linux系统--Linux网络管理与配置

Linux 网络管理与配置 在学习linux的过程中,Linux网络的管理和配置在后续学习中是很重要的,几乎学习的后期都离不开网络的概念和配置,如集群中的使用.所有学习好Linux网络至关重要. Linux网络配置有两种方式:静态指定和动态分配 动态分配就是利用DHCP服务器,动态的给linux主机分配IP地址.静态指定可以通过命令配置临时的IP和相应的NETMASK,GATEWAY,DNS等,也可以通过修改配置文件做相应的配置. 在CentOS6上的网络配置 一.静态指定,通过命令暂时配置li

Linux网络配置相关命令

写在前面: 博客书写牢记5W1H法则:What,Why,When,Where,Who,How. 本篇主要内容: ● 网络基础知识回顾 ● ifcfg系列 ifconfig route netstat ifup/ifdown ● 主机名.DNS配置 ● iproute系列 ip ss ● 网卡配置文件.路由配置文件 nmcli 计算机网络基础知识回顾: TCP/IP: TCP/IP协议体系结构是专门针对使用TCP/IP协议簇的广域计算机网络而开发的,是OSI/RM的改进版本.被大范围使用,但并非国

三大家族轻松管理CentOS 7网络属性配置

一.简单介绍    在CentOS 7中对网络管理还是有不少变化的,例如管理服务的命令变为systemctl,许多命令可以更改后直接生效,还有许多独有的工具,本文以CentOS 6与CentOS 7对比进行讲解,下面现总体介绍一下网络属性配置工具. ifcfg家族 ifcofnig:配置IP,NETMASK route:路由 netstat:状态及统计数据查看 iproute家族 ip OBJECT: addr: 地址和掩码 link:接口 route:路由 ss:状态及统计数据查看 CentO

Linux之网络管理(8)网络监控工具

Linux之网络管理(8)网络监控工具 linux中有很多查看网络.进程通信状态的查看工具,而网络之间建立通信是通过soket套接字进行的,所谓套接字,就是相当于插座,而一台主机上会产生多种套接字,就是相当于插头向插座插入的过程,也就是主机中进程通信.而在网络中建立通信,就是双方各种插入对方.当然这些只是粗率的比喻,实际上,soket是用来将tcp/udp等协议发送的数据包进行封装:也就是相当于食品包装,把数据包加上port端口号.进程号等然后发送给对方,然后对方根据数据的包装袋来放回特定需要的

网络配置命令

网卡相关 网络接口识别并命名相关的udev 配置文件: /etc/udev/rules.d/70-persistent-net.rules 查看网卡: dmesg |grep –i eth dmesg - print or control the kernel ring buffer dmesg [-c] [-r] [-n level] [-s bufsize] ethtool -i eth0 ethtool - query or control network driver and hardw

linux 操作系统调优

一 CPU 调优 1 系统拓扑 1 概述 在现代计算机技术中,大部分的系统都是拥有多个处理器的,多个处理器之间的连接并连接其他资源则需要通过系统拓扑来调节以产生影响 2 现代计算机技术的两种拓扑类型 1 SMP(对称多处理器) SMP(对称多处理器)拓扑允许所有的处理器同时访问内存,然而,由于内存访问权限的共享性和平等性,固然会迫使所有的CPU和SMP系统序列化的内存访问权限局限性能加,目前这种情况是不被接受的,因此,现在服务器系统都是NUMA(非一致性内存访问)机制. 2 NUMA 拓扑(非一

命令行工具--ss

目录 一.介绍 二.优点 三.用法 四.案例 1.列出已建立的连接 2.显示监听套接字 3.显示进程 4.不解析服务名称 5.解析数字地址/端口 6.IPv4套接字 7.IPv6套接字 8.只显示TCP 9.显示UDP 10. Unix套接字 11.显示所有信息 12.显示套接字内存使用情况 13.显示TCP内部信息 14.显示统计信息 15.基于状态的过滤器 16.根据端口号进行过滤 17.显示SELinux上下文 18.显示版本号 19.显示帮助文档信息 20.显示扩展信息 21.显示计时器

Linux ss命令详解

ss是Socket Statistics的缩写.顾名思义,ss命令可以用来获取socket统计信息,它可以显示和netstat类似的内容.ss的优势在于它能够显示更多更详细的有关TCP和连接状态的信息,而且比netstat更快速更高效. 当服务器的socket连接数量变得非常大时,无论是使用netstat命令还是直接cat /proc/net/tcp,执行速度都会很慢. ss快的秘诀在于,它利用到了TCP协议栈中tcp_diag.tcp_diag是一个用于分析统计的模块,可以获得Linux 内核