How to track traffic on my server in real time?

I was wondering if I deploy a server at home, with apache2. I would like to know how much traffic is currently on my site, in real time.

Please and thank you.

:)


You can install the package iptraf which gives you realtime monitoring of various tcp and udp information. Page hits are realtime logged in the apache log that you have configured. You can either scan that file for number of lines matching your time period, or you can use some like piwik for your apache server which gives you analysis similar to google analytics.


I frequently add the status module to my apache configuration so that I can examine the running state of Apache (this example restricts access to only localhost status requests).

This goes in the virtualhost configuration:

 # Server status
 <IfModule mod_status.c>
  <Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from localhost
  </Location>
 </IfModule>

This goes in the general server configuration (I used /etc/apache2/conf.d/10status.conf):

# Turn on extended status collection
<IfModule mod_status.c>
    ExtendedStatus On
</IfModule>

And then I make sure mod_status is enabled:

sudo a2enmod status

After that, I can just visit http://your-virtual-host.example.com/server-status and get all kinds of details, including the high-level summary, like this:

Server uptime: 7 days 22 hours 56 minutes 45 seconds
Total accesses: 292855 - Total Traffic: 5.6 GB
CPU Usage: u85.78 s8.21 cu1.49 cs0 - .0139% CPU load
.426 requests/sec - 8.5 kB/second - 19.9 kB/request
2 requests currently being processed, 8 idle workers
....
Srv PID Acc M   CPU     SS  Req Conn    Child   Slot    Client  VHost   Request
0-1 27078   0/9/21119   _   0.06    3   101 0.0 0.04    372.17  67.195.113.233  example.com GET /foo.php?state=ND&thing=Madison
1-1 -   0/0/21273   .   0.01    137 0   0.0 0.00    402.35  128.61.99.146   example.com GET /favicon.ico HTTP/1.1
....

I especially like the requests/sec, and the detailed report about what URLs are being (or were recently) served.


I would recommend using apachetop, unfortunately it seems the development stopped, but it works well.

This site is more recent.


If every 5 minutes or so is realtime enough for you, take a look at Munin. It collects system information and displays them in nice graphs, see here for a live example-installation.

alt text


ssh root@HOST tcpdump -U -s0 -w - 'not port 22' | wireshark -k -i -

HOST = your webserver Chose Statistics fro Menu and Click IO Graphs