[CentOS] count of active tcp sockets?

Wed Apr 16 21:29:29 UTC 2008
Ross S. W. Walker <rwalker at medallion.com>

J Potter wrote:
> > netstat -an|grep TIME_WAIT|wc  ?
> I need to avoid anything that lists out all the connections -- the  
> above would take too long if there are tens of thousands of 
> connections.
> I'm hoping there's a proc entry that has a summary count of the  
> current number of connections?

With the -n added to the option it won't resolve IPs so it
shouldn't take that long, but otherwise:

cat /proc/net/sockstat
sockets: used 284
TCP: inuse 16 orphan 0 tw 0 alloc 18 mem 1
UDP: inuse 12
RAW: inuse 1
FRAG: inuse 0 memory 0

I believe the tw is the time_wait count, just:

awk '/TCP:/ {print $7}' /proc/net/sockstat


This e-mail, and any attachments thereto, is intended only for use by
the addressee(s) named herein and may contain legally privileged
and/or confidential information. If you are not the intended recipient
of this e-mail, you are hereby notified that any dissemination,
distribution or copying of this e-mail, and any attachments thereto,
is strictly prohibited. If you have received this e-mail in error,
please immediately notify the sender and permanently delete the
original and any copy or printout thereof.