Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mds1256

macrumors regular
Original poster
Apr 9, 2011
167
43
Hi, currently running a test site from my macbook pro using MAMP, would like to see how many users are currently connected to it.

Is there any easy way to see these connections
 
Try visiting http://localhost:80/server-status on your MacBook Pro that's serving the site.

It depends on mod_status being enabled on your Apache installation (I don't know if it is by default - it's definitely enabled on my OS X Server installation).

Note that also this page can only be accessed via localhost. If after entering the above URL your browser resolves the 'localhost' to something else (e.g. http://yourdomain.com/) then you'll more than likely see a Forbidden error. Instead, try visiting http://127.0.0.1:80/server-status

Cheers,
Chris
 
I would use netstat from the terminal and grep on established and on 80 to see how many connections are in the established state. You can wrap a while command and/or a sleep command to see this info at certain intervals.
 
Thanks but came back as a 404



Try visiting http://localhost:80/server-status on your MacBook Pro that's serving the site.

It depends on mod_status being enabled on your Apache installation (I don't know if it is by default - it's definitely enabled on my OS X Server installation).

Note that also this page can only be accessed via localhost. If after entering the above URL your browser resolves the 'localhost' to something else (e.g. http://yourdomain.com/) then you'll more than likely see a Forbidden error. Instead, try visiting http://127.0.0.1:80/server-status

Cheers,
Chris
 
Have you got an example of the commands i need to type in for this?

not sure how to tie netstat and grep together
Thanks

I would use netstat from the terminal and grep on established and on 80 to see how many connections are in the established state. You can wrap a while command and/or a sleep command to see this info at certain intervals.
 
No way to test this command right now, but try this:

Netstat -an | grep -i est | grep -i 80


If you run netstat -an you can see a good amount of info, but it won't be filtered. If you want just a specific count of connections, you can then pipe the above command to wc like this:

Netstat -an | grep -i est | grep -i 80 | wc -l

Use it after verifying that what comes back from the first command.

You can also try netstat -anp to get the process information as well (http). For more info, you can just look at the man page: man netstat

This *should* get you what you want, again, no way for me to test right now. Let us know how it goes.
 
That works a treat!! :)

Ok one other question and I wont bother you again :cool:

How can i create a while loop to run this, not familiar with terminal at all but I know it will be possibly something like this:

while(1=1)
{
Netstat -an | grep -i est | grep -i 80
}


but not sure how to script this up etc.

Can you also limit the results to show inbound requests only?

Thanks again!


No way to test this command right now, but try this:

Netstat -an | grep -i est | grep -i 80


If you run netstat -an you can see a good amount of info, but it won't be filtered. If you want just a specific count of connections, you can then pipe the above command to wc like this:

Netstat -an | grep -i est | grep -i 80 | wc -l

Use it after verifying that what comes back from the first command.

You can also try netstat -anp to get the process information as well (http). For more info, you can just look at the man page: man netstat

This *should* get you what you want, again, no way for me to test right now. Let us know how it goes.
 
Last edited:
While true; do Netstat -an | grep -i est | grep -i 80; sleep 5

(Sleeps for number of seconds)

I think that syntax is right. If not, just do a search for while true in google, plenty of examples will come up.

For your second question, type "man netstat" in the terminal and see if there are any other switches of use to you. You will also see that netstat has a switch in there to have nestat display connection information on an interval (-c or delay).

Let us know how you make out.
 
cool, the syntax was:

while true; do netstat -an | grep -i est | grep -i 80; sleep 5; done;

thanks again, will keep looking to see if i can get inbound only.



While true; do Netstat -an | grep -i est | grep -i 80; sleep 5

(Sleeps for number of seconds)

I think that syntax is right. If not, just do a search for while true in google, plenty of examples will come up.

For your second question, type "man netstat" in the terminal and see if there are any other switches of use to you. You will also see that netstat has a switch in there to have nestat display connection information on an interval (-c or delay).

Let us know how you make out.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.