How do I check how many HTTP connections are open currently? [closed]

I want to know how many people are connected to my server. Since I'm doing comet applications, this is important


Solution 1:

There are about a zillion ways to do this but:

netstat | grep http | wc -l

Keep it mind that http is a stateless protocol. Each line can represent one client opening multiple sockets to grab different files (css, images, etc) that will hang out for awhile in a timewait state.

Solution 2:

Below are some commands of netstat using which you can check the number of connections a server has.

To display all active Internet connections to the servers, only established connections are included.

netstat -na

To display only active Internet connections to the server at port 80 and sort the results, allow to recognize many connections coming from one IP

netstat -an | grep :80 | sort

To display the list of the all IP addresses involved instead of just count.

netstat -n -p | grep SYN_REC | sort -u

Solution 3:

If your webserver is apache, you can also use the server-status page (after enabled it).

Solution 4:

I know this is an old question, but I found it while looking for a tidy way to count all incoming connections to a given port. The trouble with a blanket search for a port is that you'll also pick up outgoing connections, skewing your numbers.

Eg:

tcp        0      0 10.224.38.158:8080          10.225.239.6:38194          ESTABLISHED
tcp        0      0 10.224.38.158:8080          10.225.239.6:56825          ESTABLISHED
tcp        0      0 10.224.38.158:51512         10.226.194.28:8080          ESTABLISHED
tcp        0      0 10.224.38.158:51960         10.226.194.28:8080          TIME_WAIT
tcp        0      0 10.224.38.158:46937         10.226.194.28:8080          ESTABLISHED
tcp        0      0 10.224.38.158:51331         10.226.194.28:8080          TIME_WAIT
tcp        0      0 10.224.38.158:8080          10.225.239.6:29634          ESTABLISHED

An indiscriminate grep -c or awk | wc -l would return "7," but there are actually only "3" inbound connections. Anyway, I haven't found a graceful way to do this, and my awk-fu's not so not, but I ultimately opted to netstat -an, use awk to print only the "local address" column, and count the instances of the port I'm looking for.

netstat -an | grep -c 8080

OUTPUT : 91

netstat -an | awk '{print $4}' | grep -c 8080

OUTPUT : 31

So, 31 connected sockets on port 8080. I hope that helps. If anyone knows a more concise way to do this, then please do share it.