Monday, December 17, 2007


MRTG for SQUID gives you a detail idea of what is happening behind the scene. In this tutorial I'll make sure that you will successfully set up one like below.

First thing is to make sure that you have given --enable-snmp option while compiling your squid. If you have not done so then its time to do so. Compile your squid with --enable-snmp and then 'make clean', 'make', and 'make install'

Edit you squid.conf file so that
snmp_port 3401
acl snmppublic snmp_community public
snmp_access allow snmppublic localhost
snmp_access deny allThe first line defines the port SNMP is listening on squid.
Second line defines public as the community string or lets say password.
Third line defines that from localhost snmp query can be made to squid.
Fourth line denies query from all.(except localhost)
Now you need a web server to serve the graphs.

Download apache from
mv ./httpd-2.2.6.tar.bz2 /usr/local/src
cd /usr/local/src
bunzip2 -c /usr/local/src/httpd-2.2.6.tar.bz2 | tar xvf -
rm httpd-2.2.6.tar.bz2
mv httpd-* httpd
cd httpd
./configure --enable-prefix=/usr/local/httpd
make install

Now you need to configure apache. Lets just host it in a simple way.

mkdir -p /usr/local/www/mrtg
vi /us/local/httpd/conf/httpd.conf
Change DocumentRoot to "/usr/local/www/mrtg"
save and exit
run /usr/local/httpd/bin/apachectl -k start

Now its time for setting MRTG server. Download the following programs: (gzip (libpng) (gd) (mrtg)

Copy zlib to /usr/local/src
gunzip -c zlib-*.tar.gz | tar xvf -
rm zlib-*.tar.gz
mv zlib-* zlib
cd zlib
cd ..

Copy libppng to /usr/local/src
gunzip -c libpng-*.tar.gz |tar xvf -
rm libpng-*.tar.gz
mv libpng-* libpng
cd libpng
make -f scripts/makefile.std CC=gcc ZLIBLIB=../zlib ZLIBINC=../zlib
rm *.so.* *.so
cd ..

The \ in the following line means that they are same line.Copy gd to /usr/local/src
gunzip -c gd-2.0.11.tar.gz |tar xf -
mv gd-2.0.11 gd
cd gd
env CPPFLAGS="-I../zlib -I../libpng" LDFLAGS="-L../zlib -L../libpng" \
./configure --disable-shared --without-freetype --without-jpeg
cp .libs/* .
cd ..

Copy mrtg to /usr/local/src
gunzip -c mrtg-2.15.2.tar.gz | tar xvf -
cd mrtg-2.15.2
./configure --prefix=/usr/local/mrtg-2 \
--with-gd=/usr/local/src/gd \
--with-z=/usr/local/src/zlib \
make install
mkdir -p /usr/localmrtg-2/cfg

Now lets make graph for squid.

Download the following two files


Copy them to /usr/local/mrtg-2/cfg/
edit mrtg-squid.cfg and do as the file says. Put working dir as /var/www/mrtg

Lets make graph
/usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/cfg/mrtg-squid.cfg
Run this for three times. Its OK for now to see few errors.

Lets make index page
/usr/locl/mrtg-2/bin/indexmaker --title="OSR" --show=day --section=title --output=/var/www/mrtg/index.html /usr/local/mrtg-2/cfg/mrtg-squid.cfg

Fire your browser and you should see the graph

For continous monitoring
crontab -e
*/5 * * * *
/usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/cfg/mrtg-squid.cfg --logging=/var/log/mrtg.log

Additional reading:


  1. Nice. Very easy tutorial. Thanks

  2. Kindly advise what does the following means:

    " HTTP all service time"

    " HTTP miss service time"

    " HTTP near miss service time"

    " HTTP hit service time"

    Thank you.

  3. " HTTP all service time"
    Total time taken for the request including DNS, cached objects, new objects.

    " HTTP miss service time"
    Total time taken to retrieve objects that are not in the cache.

    " HTTP near miss service time"

    " HTTP hit service time"
    Total time taken to serve objects from cache.

  4. thank you for the reply. so if the http all service time graph show the following:

    Median Svc Time 219.0ms(Max) 17.0ms(Avg) 23.0(Current)

    Am I right to say that the squid proxy is responding to each users' request at an average of 17.0ms and at 23.0ms currently???


  5. would like to know how was the HTTP all service time being determine, how was it being calculated/showed in graph and can this timing be found in the access log???

  6. Hi, Please check

  7. thank you for the page. As I am using common logfile and there is a parameter %tr. Is this parameter the same as the total time in native log??? Kindly also advise how can I find out the maximum server requests or maximum number of clients that a server with dual CPUs and 2GB RAM can support???

  8. I recommend you going through this site,