Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm doing some comet benchmarks and would like to see how many open connections I have.

Actually I use netstat:

netstat -ant | grep 8080 | grep EST | wc -l

But it needs around 4-6 minutes to list the number, is there any tool that can do show it in real time? The number of open connections is between 100'000 - 250'000.

share|improve this question
    
Based on what you're trying to accomplish, have you considered using NetFlow and an analyzer tool? –  SpacemanSpiff Dec 13 '11 at 22:15
    
@SpacemanSpiff I hope there is some easy solution, but I will take a look on NetFlow as I'm not sure if is working with a HP switch. –  Nenad Dec 13 '11 at 22:20
    
You know, I wonder if a perfmon or WMI query might bring this data back from the TCP stack faster... still... are you after open ports or active data transfers? –  SpacemanSpiff Dec 13 '11 at 22:22
    
@SpacemanSpiff I'm after open ports looking –  Nenad Dec 13 '11 at 22:27
    
Maybe an SNMP query?... just throwing out ideas for you. –  SpacemanSpiff Dec 13 '11 at 22:41
show 1 more comment

4 Answers

up vote 4 down vote accepted

don't know if lsof is better, but give this a try:

lsof-ni:8080 -sTCP:ESTABLISHED | wc -l
share|improve this answer
    
actually lsof take 5 sec, but I have 20'000 connections and counting :-) will let you know how long after pass 100K –  Nenad Dec 13 '11 at 22:28
    
update: have some issues with our comet clients, but lsof is much faster 10 sec for 30'000 connections, will update after I fixed the comet issues and was able to check above 100K connections –  Nenad Dec 13 '11 at 22:35
    
update: 15sec to show 130'000 connections - thank you! This do the job for me for more detailed solution a network analyzer must be used. –  Nenad Dec 13 '11 at 22:51
    
wonderfull! You could also use the switch -t - perhaps this will give you also a little boost. –  ThorstenS Dec 14 '11 at 6:07
add comment

Another option would be to read /proc/net/tcp directly. To see all established TCP connections on, 8080, you would do something like

$ printf %04X 8080
1F90
$ grep :1F90 /proc/net/tcp | grep ' 01 ' | wc -l

If you want to do it in a single process (less IO overhead) and handle corner cases, the following tells you how many ESTABLISHED TCP connections have local port 8080:

$ perl -anle '
          $F[1] =~ /:1F90/ and $F[3] =~ /01/ and $cnt++;
          END { print 0+$cnt }
         '  /proc/net/tcp

If the software on your machine listening on 8080 has IPv6 support, you'll need to read /proc/net/tcp6 also; if the program's using IPv6 sockets, connections will show up there even if they're using IPv4.

share|improve this answer
add comment

more easy is

#netstat -at | wc -l

It will display number of TCP connection on system...

share|improve this answer
    
This will take longer since you're not using the "n" flag to stop it from looking up all hostnames. It will also show other things than the port 8080 connections that the question was about. –  Jenny D Feb 27 '13 at 10:48
add comment

If you just need to see connecton statistics, try ss utility from iproute suite:

# ss -s
Total: 1788 (kernel 3134)
TCP:   1638 (estab 1409, closed 162, orphaned 0, synrecv 0, timewait 127/0), ports 0

Transport Total     IP        IPv6
*         3134      -         -        
RAW       0         0         0        
UDP       74        69        5        
TCP       1476      1444      32       
INET      1550      1513      37       
FRAG      0         0         0     

You also can view detailed information on all established connections like this:

ss -n state established

…or ssh connections only:

ss -n state established '( dport = :ssh or sport = :ssh )'

Some numbers section at the bottom of this page may also interest you.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.