Setup Squid MRTG on Ubuntu 10.10

Update Feb 23: to install only MRTG and SNMP please read this article.

 

Install MRTG, Apache2, Squid and SNMP

$ sudo apt-get install apache2 snmpd mrtg snmp-mibs-downloader squid

Configure SNMP

Backup /etc/snmp/snmpd.conf

$ sudo mv /etc/snmp/snmpd.conf /etc/snmp/snmpd.conf.bak

Create new /etc/snmp/snmpd.conf

$ sudo nano /etc/snmp/snmpd.conf

and key in these lines:

rocommunity  public
syslocation  "Bukit Batok"
syscontact  xxxxxx@yahoo.com
com2sec public localhost public
group public v1 public
group public v2c public
group public usm public
view all included .1
access public "" any noauth exact all none none

Edit /etc/default/snmpd:

$ sudo nano /etc/default/snmpd

and make sure it contains these lines:

SNMPDRUN=yes
SNMPDOPTS='-Lsd -Lf /dev/null -u snmp -g snmp -I -smux -p /var/run/snmpd.pid -c /etc/snmp/snmpd.conf'
SNMPDCOMPAT=yes

Configure Squid

Edit /etc/squid/squid.conf

$ sudo nano /etc/squid/squid.conf

and make sure these lines exist:

snmp_port 3401
acl snmppublic snmp_community public
snmp_access allow snmppublic all

Restart Squid:

$ sudo /usr/sbin/squid -k reconfigure

Configure MRTG

Create configuration file:

$ sudo cfgmaker --global 'WorkDir:/var/www/mrtg' --ifref=name --ifdesc=eth --global 'Options[_]: bits' --output /etc/mrtg.cfg  --snmp-options=:::::1 public@localhost

Edit /etc/mrtg.cfg and make sure these lines exist:

### Global Config Options
WorkDir: /var/www/mrtg
RunAsDaemon: yes
EnableIPv6: no
Options[_]: bits
LoadMIBS: /usr/share/snmp/mibs/SQUID.txt
### Squid Config
Target[proxy-hit]: cacheHttpHits&cacheServerRequests:public@localhost:3401
# If you are using Squid 2.6 or later, uncomment the following line
RouterName[proxy-hit]: cacheUniqName
MaxBytes[proxy-hit]: 100000
Title[proxy-hit]: HTTP Hits
PageTop[proxy-hit]: <H1>proxy Cache Statistics: HTTP Hits/Requests</H1>
<TABLE>
<TR><TD>System:</TD><TD>saniya</TD></TR>
<TR><TD>Maintainer:</TD><TD>kumkum</TD></TR>
<TR><TD>Description:</TD><TD>Squid Proxy server</TD></TR>
</TABLE>
Suppress[proxy-hit]: y
LegendI[proxy-hit]:  HTTP hits
LegendO[proxy-hit]:  HTTP requests
Legend1[proxy-hit]:  HTTP hits
Legend2[proxy-hit]:  HTTP requests
YLegend[proxy-hit]: perminute
ShortLegend[proxy-hit]: req/min
Options[proxy-hit]: nopercent, perminute, dorelpercent, unknaszero

Target[proxy-srvkbinout]: cacheServerInKb&cacheServerOutKb:public@localhost:3401
# If you are using Squid 2.6 or later, uncomment the following line
RouterName[proxy-srvkbinout]: cacheUniqName
MaxBytes[proxy-srvkbinout]: 76800
Title[proxy-srvkbinout]: Cache Server Traffic In/Out
PageTop[proxy-srvkbinout]: <H1>Cache Statistics: Server traffic volume (In/Out)</H1>
<TABLE>
<TR><TD>System:</TD><TD>saniya</TD></TR>
<TR><TD>Maintainer:</TD><TD>kumkum</TD></TR>
<TR><TD>Description:</TD><TD>Squid Proxy server</TD></TR>
</TABLE>
Suppress[proxy-srvkbinout]: y
LegendI[proxy-srvkbinout]:  Traffic In
LegendO[proxy-srvkbinout]:  Traffic Out
Legend1[proxy-srvkbinout]:  Traffic In
Legend2[proxy-srvkbinout]:  Traffic Out
YLegend[proxy-srvkbinout]: per minute
ShortLegend[proxy-srvkbinout]: b/min
kMG[proxy-srvkbinout]: k,M,G,T
kilo[proxy-srvkbinout]: 1024
Options[proxy-srvkbinout]: nopercent, perminute, unknaszero

Create MRTG index file:

$ sudo indexmaker /etc/mrtg.cfg > /var/www/mrtg/index.html

Execute MRTG:

$ env LANG=C /usr/bin/mrtg /etc/mrtg.cfg

MRTG will default graph the data every 5 minutes.
To change this interval into 10 minutes, add this line into mrtg.cfg:
Interval : 10

To view MRTG graphs, go to http://localhost/mrtg/

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.