linux 统计sendq数量,Linux服务器当前各种TCP网络连接状态的统计

例如服务器上的TCP网络连接状态显示如下:

[root@huzhenwei ~]# netstat -nat

Active Internet connections (servers and established)

Proto Recv-Q Send-Q Local Address               Foreign Address             State

tcp        0      0 0.0.0.0:10050               0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:554                 0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:1935                0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:8080                0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:3001                0.0.0.0:*                   LISTEN

tcp        0      0 0.0.0.0:1947                0.0.0.0:*                   LISTEN

tcp        0      0 172.16.6.93:80              172.16.6.93:51201           ESTABLISHED

tcp        0      0 172.16.6.93:80              172.16.6.93:51202           ESTABLISHED

tcp        0      0 172.16.6.93:10050           172.16.3.112:32769          TIME_WAIT

tcp        0      0 172.16.6.93:51201           172.16.6.93:80              ESTABLISHED

tcp        0      0 172.16.6.93:51202           172.16.6.93:80              ESTABLISHED

tcp        0      1 172.16.6.93:53276           172.16.3.162:8080           SYN_SENT

tcp        0      0 :::22                       :::*                        LISTEN

tcp        0    844 ::ffff:172.16.6.93:22       ::ffff:172.16.1.36:56495    ESTABLISHED

统计命令和计算结果如下:

[root@huzhenwei ~]# netstat -nat | awk 'FNR>2{print $NF}' | sort | uniq -c

5 ESTABLISHED

9 LISTEN

1 TIME_WAIT

参数说明:

netstat -nat参数t表示只列出tcp连接

awk 'FNR>2{print $NF}'  FNR表示这条记录的行号,NF表示这一条记录中的字段总数

TCP连接状态的定义:

ESTABLISHED

The socket has an established connection.

SYN_SENT

The socket is actively attempting to establish a connection.

SYN_RECV

A connection request has been received from the network.

FIN_WAIT1

The socket is closed, and the connection is shutting down.

FIN_WAIT2

Connection is closed, and the socket is waiting for a shutdown from the remote end.

TIME_WAIT

The socket is waiting after close to handle packets still in the network.

CLOSED The socket is not being used.

CLOSE_WAIT

The remote end has shut down, waiting for the socket to close.

LAST_ACK

The remote end has shut down, and the socket is closed. Waiting for acknowledgement.

LISTEN The  socket is listening for incoming connections.  Such sockets are not included in the output

unless you specify the --listening (-l) or --all (-a) option.

CLOSING

Both sockets are shut down but we still don’t have all our data sent.

UNKNOWN

The state of the socket is unknown.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值