Linux中檢視socket狀态:
cat /proc/net/sockstat #(這個是ipv4的)
sockets: used 137 TCP: inuse 49 orphan 0 tw 3272 alloc 52 mem 46UDP: inuse 1 mem 0RAW: inuse 0 FRAG: inuse 0 memory 0
說明:
sockets: used:已使用的所有協定套接字總量
TCP: inuse:正在使用(正在偵聽)的TCP套接字數量。其值≤ netstat –lnt | grep ^tcp | wc –l
TCP: orphan:無主(不屬于任何程序)的TCP連接配接數(無用、待銷毀的TCP socket數)
TCP: tw:等待關閉的TCP連接配接數。其值等于netstat –ant | grep TIME_WAIT | wc –l
TCP:alloc(allocated):已配置設定(已建立、已申請到sk_buff)的TCP套接字數量。其值等于netstat –ant | grep ^tcp | wc –l
TCP:mem:套接字緩沖區使用量(機關不詳。用scp實測,速度在4803.9kB/s時:其值=11,netstat –ant 中相應的22端口的Recv-Q=0,Send-Q≈400)
UDP:inuse:正在使用的UDP套接字數量
RAW:
FRAG:使用的IP段數量
IPv6請看:cat /proc/net/sockstat6
TCP6: inuse 3UDP6: inuse 0RAW6: inuse 0 FRAG6: inuse 0 memory 0
通過這些值,可以很容易計算出目前的tcp請求數,然後做相關的監控。
本文轉自 憬薇 51CTO部落格,原文連結:http://blog.51cto.com/welcomeweb/1975358