Monitoring Squid With MRTG Using SNMP ===================================== Shanker Balan http://shankerbalan.com/ Changelog: Fri Jun 6 14:27:58 IST 2003 - Added "snmpwalk" usage from net-snmp-5 * Fri Aug 24 10:26:40 IST 2001 - Initial rollout SYNOPSIS: Monitor Squid Cache server. DESCRIPTION: Squid version 2.2 and later is SNMP capable. By using an SNMP monitoring program like MRTG, it is possible to draw interesting graphs and gather statistics of the Squid cache server. REQUIREMENTS: Squid > v2.2 compiled with SNMP support ( RHL 7.1 Disc #1 ) MRTG ( RHL 7.1 PowerTools ) INSTALLATION: The Squid RPM shipped with RHL 7.1 has SNMP support compiled in. Install squid and mrtg RPMS. # rpm -ivh squid-2.3.STABLE4-10.i386.rpm # rpm -ivh mrtg-2.9.6-2.i386.rpm I assume that Squid has been configured to work in your environment and you just want to add in SNMP monitoring. CONFIGURATION: The configuration part is to be done in 2 phases - (1) Enable SNMP on Squid (2) Configure MRTG to monitor Squid using SNMP Step1: Configuring Squid 2.2 Edit the squid config file (squid.conf) and change the SNMP ACL lines to look like this: -- squid.conf -- snmp_port 3401 acl snmppublic snmp_community public snmp_access allow snmppublic localhost snmp_access deny all -- squid.conf -- Restart squid # service squid restart Check the squid cache.log (/var/log/squid/cache) for any SNMP related messages. You should see this: 2001/08/24 10:46:02| Starting Squid Cache version 2.3.STABLE4 for i386-redhat-linux-gnu... [..] 2001/08/24 10:46:03| Accepting HTTP connections at 0.0.0.0, port 8000, FD 13. 2001/08/24 10:46:03| Accepting ICP messages at 0.0.0.0, port 3130, FD 14. 2001/08/24 10:46:03| Accepting SNMP messages on port 3401, FD 15. [..] See: (1) Squid FAQ 18.2: Enabling SNMP in Squid TESTING: Step1: Query Squid using "snmpwalk" If SNMP has been enabled on Squid and the ACL have been defined correctly, the following command will return a similar output - # snmpwalk -p 3401 localhost public .1.3.6.1.4.1.3495.1.1 If it gives output like: enterprises.3495.1.1.1.0 = 120 enterprises.3495.1.1.2.0 = 82692 enterprises.3495.1.1.3.0 = Timeticks: (99027) 0:16:30.27 Use this command if you have a very recent version of net-snmp tools: [godzilla] ~# snmpwalk -V NET-SNMP version: 5.0.8 [godzilla] ~# snmpwalk -v1 -c public localhost:3401 .1.3.6.1.4.1.3495.1.1 SNMPv2-SMI::enterprises.3495.1.1.1.0 = INTEGER: 84 SNMPv2-SMI::enterprises.3495.1.1.2.0 = INTEGER: 810 SNMPv2-SMI::enterprises.3495.1.1.3.0 = Timeticks: (149104) 0:24:51.04 then it is working ok, and you should be able to make nice statistics out of it. See: (1) Squid FAQ 18.5: How can I query the Squid SNMP Agent? Now that we have Squid + SNMP working, we can procced to configure MRTG. Step2: Configuring MRTG Edit mrtg.cfg (/etc/mrtg/mrtg.cfg) and add the following lines in it: -- mrtg.cfg -- ######################################################## # Squid related sections # ######################################################## # Change this to the correct location of squid/mib.txt LoadMIBS: /etc/squid/mib.txt Target[proxy-hit]: cacheHttpHits&cacheServerRequests:public@localhost:3401 MaxBytes[proxy-hit]: 10000 Title[proxy-hit]: HTTP Hits PageTop[proxy-hit]:

Proxy Cache Statistics: HTTP Hits / Requests

System: proxy.domain.com
Maintainer: Squid Maintainer
Description:Squid Proxy server
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 MaxBytes[proxy-srvkbinout]: 10000 Title[proxy-srvkbinout]: Cache Server Traffic In / Out PageTop[proxy-srvkbinout]:

Cache Statistics: Server Traffic Volume (In/Out)

System: proxy.mydomain.com
Maintainer: Squid Maintainer
Description:Squid Proxy server
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 -- mrtg.cfg -- Run "mrtg /etc/mrtg/mrtg.cfg" thrice. Ignore the warnings. # mrtg /etc/mrtg/mrtg.cfg Rateup WARNING: /usr/bin/rateup could not read the primary log file for proxy-hit Rateup WARNING: /usr/bin/rateup The backup log file for proxy-hit was invalid as well Rateup WARNING: /usr/bin/rateup Can't remove proxy-hit.old updating log file Rateup WARNING: /usr/bin/rateup Can't rename proxy-hit.log to proxy-hit.old updating log file Rateup WARNING: /usr/bin/rateup could not read the primary log file for proxy-srvkbinout Rateup WARNING: /usr/bin/rateup The backup log file for proxy-srvkbinout was invalid as well Rateup WARNING: /usr/bin/rateup Can't remove proxy-srvkbinout.old updating log file Rateup WARNING: /usr/bin/rateup Can't rename proxy-srvkbinout.log to proxy-srvkbinout.old updating log file # mrtg /etc/mrtg/mrtg.cf Rateup WARNING: /usr/bin/rateup Can't remove proxy-hit.old updating log file Rateup WARNING: /usr/bin/rateup Can't remove proxy-srvkbinout.old updating log file # mrtg /etc/mrtg/mrtg.cf The third time there wont be any errors. TESTING: Point your browser to the following URLs to see the graphs: (1) http://localhost/mrtg/proxy-srvkbinout.html (2) http://localhost/mrtg/proxy-hit.html LOGS: None. FILES: /etc/squid/squid.conf /etc/mrtg/mrtg.cfg RPMS: squid-2.3.STABLE4-10.i386.rpm mrtg-2.9.6-2.i386.rpm SEE ALSO: There are lots of scatterred docs on Squid + MRTG floating around. I will try and add them as i dig em up. (1) Squid FAQ 18.2: Enabling SNMP in Squid (2) Squid FAQ 18.5: How can I query the Squid SNMP Agent? (3) MRTG For Squid. Includes nice mrtg.cfg files (4) Google Groups Search for Squid+MRTG (5) MRTG Homepage TODO: Curently we monitor only the following SNMP attributes: - cacheServerInKb - cacheServerOutKb - cacheHttpHits - cacheServerRequests This is only the tip of the iceberg. There are many many more attributes which one can monitor using SNMP. See the squid/mib.txt for a complete list of MIBs.