کد:
http://www.visolve.com/squid/whitepapers/monitoringsquid.php

Introduction


Squid runtime information like CPU usage, Memory usage, Cache Hit, Miss etc can be monitored using SNMP (a.k.a Simple Network Management Protocol). For this your squid server should have SNMP Server installed; True SNMP support is available from squid 2 and above. SNMP is normally transported through UDP packets. SNMP receives and responds to SNMP messages sent to the SNMP port on the local machine. The standard SNMP port is 161; by default Squid listens for incoming SNMP requests on port 3401.

There are a number of tools used to monitor Squid via SNMP, among which MRTG is mostly used. The Multi Router Traffic Grapher (MRTG) is a tool to monitor squid information which generates a real-time status (graphical representation), in dynamic view by sampling data every five minutes (may vary according to your need). MRTG shows activity - in the last 24 hours and also in a weekly, monthly and yearly graph.

Note: Working examples used in this document are from Linux OS. This may vary for other OS.

Enable SNMP in Squid



To use SNMP with squid, it must be enabled with the configure script, and rebuilt. To enable SNMP in squid go to squid src directory and follow the steps given below :

./configure --enable-snmp [ ... other configure options ]

make all
make install

And edit following tags in squid.conf file :

acl aclname snmp_community public
snmp_access aclname

Once you configure squid and SNMP server, Start SNMP and squid.

Querying the Squid SNMP agent

You can test if your Squid supports SNMP with the snmpwalk program (snmpwalk is a part of the UCD-SNMP project). Note that you have to specify the SNMP port, which in Squid defaults to 3401.

snmpwalk -p 3401 hostname communitystring .1.3.6.1.4.1.3495.1.1.If it gives output like :

enterprises.nlanr.squid.cacheSystem.cacheSysVMsize = 7970816
enterprises.nlanr.squid.cacheSystem.cacheSysStorag e = 2796142
enterprises.nlanr.squid.cacheSystem.cacheUptime = Timeticks: (766299) 2:07:42.99

then it is working ok, and you should be able to make nice statistics out of mrtg tool.

Installing and configuring MRTG


You can get MRTG from http://mrtg.hdl.com/pub/.Create a user for mrtg for example create a user name as mrtg and then untar the package

tar -xvzf mrtg-*

To configure, compile and install the mrtg enter the following commands :

./configure
make
make install

And run
/cfgmaker --global 'WorkDir: /home/mrtg/' --global 'Options[_]: bits,growright' --output /home/mrtg/cfg/mrtg.cfg public@ipaddress or hostname of SNMP-Squid machine

This will create a configuration file as mrtg.cfg in /home/mrtg/cfg/mrtg.cfg

Note: This example above will create an mrtg config file in /home/mrtg/cfg assuming /home/mrtg is visible on your webserver

Edit this configuration file (mrtg.cfg)
LoadMIBs: /mib.txt
And you have to set Target to get squid information.

(Note: The Squid MIB can be addressed by its root, which is 1.3.6.1.4.1.3495.1. In symbolic names, that is iso.org.dod.internet.private.enterprises.nlanr.squ id. Symbolic names are used only when interacting with people - the packet only contains the numeric MIB label.)

Running MRTG

Once you have created a configuration file, try the following :

/mrtg /mrtg.cfg

This will query your squid and also create your first mrtg traffic graphs and webpages. When you run mrtg for the first time there will be a lot of complaints about missing log files. Don't worry, this is normal for the first 2 times you start mrtg. If it keeps complaining after this time you might want to look into the problem.

Sample Screen shots generated by MRTG-SNMP.

Starting mrtg by hand is not ideal in the long run. So when you are satisfied with the results you must automate the process of running mrtg in regular intervals (this means every 5 minutes by default).

If you are using Linux, then the line may look like this if you are using crontab -e

*/5 * * * * /mrtg /mrtg.cfg

References



ViSolve Squid Configuration Manual 2.4
ViSolve Squid Configuration Manual 3.0
http://people.ee.ethz.ch/~oetiker/webtools/mrtg/
http://chrismiles.info/unix/mrtg/squidsample/
http://net-snmp.sourceforge.net




موضوعات مشابه: