Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

closed as too broad by Stefan Lasiewski, Tom O'Connor Aug 26 '13 at 23:51

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

What kind of server? What OS? If it's a web server which one? Your choice of tags really don't help at all. – John Gardeniers May 13 '11 at 4:36
Bear in mind that HTTP does not commonly maintain connections. So, users will only connect temporarily to pull a web-page, then immediately disconnect. Simply looking at open connections will not give you the number of people viewing your website. – Chris S May 13 '11 at 12:37

4 Answers 4

up vote 11 down vote accepted

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.

share|improve this answer
grep -c saves a fork. :) – HampusLi May 13 '11 at 9:35

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
share|improve this answer

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.


tcp        0      0          ESTABLISHED
tcp        0      0          ESTABLISHED
tcp        0      0          ESTABLISHED
tcp        0      0          TIME_WAIT
tcp        0      0          ESTABLISHED
tcp        0      0          TIME_WAIT
tcp        0      0          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 91

$ netstat -an | awk '{print $4}' | grep -c 8080 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.

share|improve this answer
Whenever you use awk and grep in quick succession, chances are that awk alone will do the job. netstat -an | awk '$5 ~ /:8080$/ { C++ } END { print C }' – 200_success Aug 26 '13 at 19:55

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

share|improve this answer

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