I use my own Perl script to collect stats from Squid. The stats are stored in RRDtool databases, and RRDtool also generates the graphs. Stats are collected every five minutes. Apache is configured to expire the graph image files after five minutes.
For a sample, look here.
Compile apache with the expires module:
% cd apache_1.3.3. % ./configure --add-module=src/modules/standard/mod_expires.c
Download RRDtool and unpack it.
Put poll.pl, create.sh, 1day-cgi, and htaccess somewhere under your htdocs directory.
Rename htaccess to .htaccess and make sure it is readable by all.
Rename 1day-cgi to 1day.cgi. [sorry, I can't name it .cgi here, or else my server tries to execute it].
Run the create.sh script to create the RRD databases.
Try the poll.pl script by hand:
% perl poll.pl localhost
Add it to your cron jobs:
% crontab */5 * * * * /usr/local/apache/share/htdocs/squid-rrd/poll.pl localhost ^D
Tell apache to interpret .cgi as a CGI script by editing srm.conf and uncommenting this line:
AddHandler cgi-script .cgi
Tell apache its okay to execute CGI scripts, and to set Expires headers by adding this to access.conf:
<Directory "/usr/local/apache/share/htdocs/squid-rrd"> AllowOverride Indexes Options ExecCGI <Directory>
Apache needs write access to the directory where RRD creates the PNG files. For now, this is the same directory.
% cd /usr/local/apache/share/htdocs/squid-rrd % su # chgrp nobody . # chmod 775 .
Alternatively, you can create empty PNG files and make just those files writable by nobody:
% cd /usr/local/apache/share/htdocs/squid-rrd % su # cp /dev/null connections.day.png ... # chgrp nobody *.png # chmod 775 *.png
Request 1day.cgi in your browser. You should see a number of graphs and your browser should refresh the display every 2.5 minutes.
You may want to copy 1day.cgi to another filename, such as ``1week.cgi'' and change all occurances of ``day'' to ``week'' in the new file.
As written, the CGI file requires write access for the PNG files that it creates in the same directory as the RRD files. You can put the PNG files in a separate directory on your HTTP server, but you'll need to edit the CGI file. The RRDtool documentation explains how to do this.
It would be nice if I could use snmpget instead of the gross poll.pl script. However, at this time, a number of interesting stats are not available via Squid's SNMP MIB.