# 20020605 bog@deol.ru htp://www.bog.pp.ru/work/squid.html#rrdtool

if [ -z "$2" ]
then
  start=-2days
  int=5min
else
  start=$1
  int=$2
fi
HTMLDIR=куда-помещать-графики

snmpget -On -Oq -p 3401 -m SQUID-MIB имя-хоста имя-сообщества cacheUptime | awk '{print $2}' > $HTMLDIR/squid_uptime

# cacheRequestHit и cacheRequestByte почти совпадают с вычисляемыми
# calcRequestHit и calcRequestByte
# /usr/local/bin/rrdtool graph $HTMLDIR/squid_hr_$int.png --start $start --vertical-label percents --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Hit Ratio"  DEF:cacheRequestHit=squid.rrd:cacheRequestHit:AVERAGE DEF:cacheProtoClientHtt=squid.rrd:cacheProtoClientHtt:AVERAGE DEF:cacheHttpHits=squid.rrd:cacheHttpHits:AVERAGE 'CDEF:calcRequestHit=cacheHttpHits,cacheProtoClientHtt,/,100,*' DEF:cacheRequestByte=squid.rrd:cacheRequestByte:AVERAGE DEF:cacheHttpOutKb=squid.rrd:cacheHttpOutKb:AVERAGE DEF:cacheServerInKb=squid.rrd:cacheServerInKb:AVERAGE 'CDEF:calcRequestByte=cacheHttpOutKb,cacheServerInKb,-,cacheHttpOutKb,/,100,*' 'LINE1:cacheRequestHit#0000FF:Request     ' 'GPRINT:cacheRequestHit:AVERAGE:Avg %lf' 'GPRINT:cacheRequestHit:LAST:Cur %lf\l' 'LINE1:calcRequestHit#000080:Request calc' 'GPRINT:calcRequestHit:AVERAGE:Avg %lf' 'GPRINT:calcRequestHit:LAST:Cur %lf\l' 'LINE1:cacheRequestByte#00FF00:Byte        ' 'GPRINT:cacheRequestByte:AVERAGE:Avg %lf' 'GPRINT:cacheRequestByte:LAST:Cur %lf\l' 'LINE1:calcRequestByte#008000:Byte calc   ' 'GPRINT:calcRequestByte:AVERAGE:Avg %lf' 'GPRINT:calcRequestByte:LAST:Cur %lf\l' > /dev/null
/usr/local/bin/rrdtool graph $HTMLDIR/squid_hr_$int.png --start $start --vertical-label percents --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Hit Ratio"  DEF:cacheProtoClientHtt=squid.rrd:cacheProtoClientHtt:AVERAGE DEF:cacheHttpHits=squid.rrd:cacheHttpHits:AVERAGE 'CDEF:calcRequestHit=cacheHttpHits,cacheProtoClientHtt,/,100,*' DEF:cacheHttpOutKb=squid.rrd:cacheHttpOutKb:AVERAGE DEF:cacheServerInKb=squid.rrd:cacheServerInKb:AVERAGE 'CDEF:calcRequestByte=cacheHttpOutKb,cacheServerInKb,-,cacheHttpOutKb,/,100,*' 'LINE1:calcRequestHit#0000FF:Request ' 'GPRINT:calcRequestHit:AVERAGE:Avg %lf' 'GPRINT:calcRequestHit:LAST:Cur %lf\l' 'LINE1:calcRequestByte#00FF00:Byte    ' 'GPRINT:calcRequestByte:AVERAGE:Avg %lf' 'GPRINT:calcRequestByte:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_pf_$int.png --start $start --vertical-label pages/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Page Faults" DEF:cacheSysPageFaults=squid.rrd:cacheSysPageFaults:AVERAGE 'LINE1:cacheSysPageFaults#0000FF:Page Faults' 'GPRINT:cacheSysPageFaults:AVERAGE:Avg %lf' 'GPRINT:cacheSysPageFaults:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_reads_$int.png --start $start --vertical-label reads/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid HTTP reads" DEF:cacheSysNumReads=squid.rrd:cacheSysNumReads:AVERAGE 'LINE1:cacheSysNumReads#0000FF:Reads' 'GPRINT:cacheSysNumReads:AVERAGE:Avg %lf' 'GPRINT:cacheSysNumReads:LAST:Cur %lf\l' > /dev/null

# у меня cacheCpuUsage всегда равен 3%
#/usr/local/bin/rrdtool graph $HTMLDIR/rrdtool/squid_cpu_$int.png --start $start --vertical-label percents --width 700 --step 300 --height 185 --imgformat PNG --title="Squid CPU Usage"  DEF:cacheCpuTime=squid.rrd:cacheCpuTime:AVERAGE 'CDEF:cacheCpuTimeP=cacheCpuTime,100,*' DEF:cacheCpuUsage=squid.rrd:cacheCpuUsage:AVERAGE 'LINE1:cacheCpuTimeP#0000FF:by calc ' 'GPRINT:cacheCpuTimeP:AVERAGE:Avg %lf' 'GPRINT:cacheCpuTimeP:LAST:Cur %lf\l' 'LINE1:cacheCpuUsage#7FFF00:by squid' 'GPRINT:cacheCpuUsage:AVERAGE:Avg %lf' 'GPRINT:cacheCpuUsage:LAST:Cur %lf\l' > /dev/null
/usr/local/bin/rrdtool graph $HTMLDIR/squid_cpu_$int.png --start $start --vertical-label percents --width 700 --step 300 --height 185 --imgformat PNG --title="Squid CPU Usage"  DEF:cacheCpuTime=squid.rrd:cacheCpuTime:AVERAGE 'CDEF:cacheCpuTimeP=cacheCpuTime,100,*' 'LINE1:cacheCpuTimeP#0000FF:% of CPU usage' 'GPRINT:cacheCpuTimeP:AVERAGE:Avg %lf' 'GPRINT:cacheCpuTimeP:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_objects_$int.png --start $start --vertical-label objects --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Object Count" DEF:cacheNumObjCount=squid.rrd:cacheNumObjCount:AVERAGE 'LINE1:cacheNumObjCount#0000FF:Objects' 'GPRINT:cacheNumObjCount:AVERAGE:Avg %lf' 'GPRINT:cacheNumObjCount:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_unlinks_$int.png --start $start --vertical-label unlinks/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Unlinks/s" DEF:cacheCurrentUnlink=squid.rrd:cacheCurrentUnlink:AVERAGE 'LINE1:cacheCurrentUnlink#0000FF:Unlinks' 'GPRINT:cacheCurrentUnlink:AVERAGE:Avg %lf' 'GPRINT:cacheCurrentUnlink:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_unusedfd_$int.png --start $start --vertical-label fd --width 700 --step 300 --height 185 --imgformat PNG --title="Squid FD" DEF:cacheCurrentUnusedF=squid.rrd:cacheCurrentUnusedF:AVERAGE CDEF:cacheCurrentUsedF=1024,cacheCurrentUnusedF,- 'LINE1:cacheCurrentUnusedF#0000FF:free' 'GPRINT:cacheCurrentUnusedF:AVERAGE:Avg %lf' 'GPRINT:cacheCurrentUnusedF:LAST:Cur %lf\l' 'LINE1:cacheCurrentUsedF#FF0000:used' 'GPRINT:cacheCurrentUsedF:AVERAGE:Avg %lf' 'GPRINT:cacheCurrentUsedF:LAST:Cur %lf\l'> /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_request_$int.png --start $start --vertical-label requests/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Requests"  DEF:cacheProtoClientHtt=squid.rrd:cacheProtoClientHtt:AVERAGE DEF:cacheHttpHits=squid.rrd:cacheHttpHits:AVERAGE DEF:cacheServerRequests=squid.rrd:cacheServerRequests:AVERAGE 'LINE1:cacheProtoClientHtt#0000FF:from clients' 'GPRINT:cacheProtoClientHtt:AVERAGE:Avg %lf' 'GPRINT:cacheProtoClientHtt:LAST:Cur %lf\l' 'LINE1:cacheHttpHits#00FF00:hits        ' 'GPRINT:cacheHttpHits:AVERAGE:Avg %lf' 'GPRINT:cacheHttpHits:LAST:Cur %lf\l' 'LINE1:cacheServerRequests#FF0000:to servers  ' 'GPRINT:cacheServerRequests:AVERAGE:Avg %lf' 'GPRINT:cacheServerRequests:LAST:Cur %lf\l'> /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_errors_$int.png --start $start --vertical-label errors/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Errors/s"  DEF:cacheHttpErrors=squid.rrd:cacheHttpErrors:AVERAGE DEF:cacheServerErrors=squid.rrd:cacheServerErrors:AVERAGE 'LINE1:cacheHttpErrors#0000FF:client' 'GPRINT:cacheHttpErrors:AVERAGE:Avg %lf' 'GPRINT:cacheHttpErrors:LAST:Cur %lf\l' 'LINE1:cacheServerErrors#7FFF00:server' 'GPRINT:cacheServerErrors:AVERAGE:Avg %lf' 'GPRINT:cacheServerErrors:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_traffic_$int.png --start $start --vertical-label Kbytes/s --base 1024 --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Traffic"  DEF:cacheHttpOutKb=squid.rrd:cacheHttpOutKb:AVERAGE DEF:cacheServerInKb=squid.rrd:cacheServerInKb:AVERAGE 'LINE1:cacheHttpOutKb#0000FF:to client  ' 'GPRINT:cacheHttpOutKb:AVERAGE:Avg %lf' 'GPRINT:cacheHttpOutKb:LAST:Cur %lf\l' 'LINE1:cacheServerInKb#7FFF00:from server' 'GPRINT:cacheServerInKb:AVERAGE:Avg %lf' 'GPRINT:cacheServerInKb:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_swapsize_$int.png --base 1024 --start $start --vertical-label KB --width 700 --step 300 --height 185 --imgformat PNG --title="Squid Swap Size" DEF:cacheCurrentSwap=squid.rrd:cacheCurrentSwap:AVERAGE 'LINE1:cacheCurrentSwap#0000FF:Swap' 'GPRINT:cacheCurrentSwap:AVERAGE:Avg %lf' 'GPRINT:cacheCurrentSwap:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_svctime_$int.png --start $start --vertical-label ms --width 700 --step 300 --height 185 --imgformat PNG --title="Squid average Service Time"  DEF:cacheHttpAllSvcTime=squid.rrd:cacheHttpAllSvcTime:AVERAGE DEF:cacheHttpMissSvc=squid.rrd:cacheHttpMissSvc:AVERAGE DEF:cacheHttpHitSvcTime=squid.rrd:cacheHttpHitSvcTime:AVERAGE DEF:cacheDnsSvcTime=squid.rrd:cacheDnsSvcTime:AVERAGE 'LINE1:cacheHttpAllSvcTime#0000FF:all ' 'GPRINT:cacheHttpAllSvcTime:AVERAGE:Avg %lf' 'GPRINT:cacheHttpAllSvcTime:LAST:Cur %lf\l' 'LINE1:cacheHttpMissSvc#00FF00:miss' 'GPRINT:cacheHttpMissSvc:AVERAGE:Avg %lf' 'GPRINT:cacheHttpMissSvc:LAST:Cur %lf\l' 'LINE1:cacheHttpHitSvcTime#FF0000:hit ' 'GPRINT:cacheHttpHitSvcTime:AVERAGE:Avg %lf' 'GPRINT:cacheHttpHitSvcTime:LAST:Cur %lf\l' 'LINE1:cacheDnsSvcTime#00FFFF:DNS ' 'GPRINT:cacheDnsSvcTime:AVERAGE:Avg %lf' 'GPRINT:cacheDnsSvcTime:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_ipentries_$int.png --start $start --vertical-label entries --width 700 --step 300 --height 185 --imgformat PNG --title="Squid IP Entries" DEF:cacheIpEntries=squid.rrd:cacheIpEntries:AVERAGE 'LINE1:cacheIpEntries#0000FF:Entries' 'GPRINT:cacheIpEntries:AVERAGE:Avg %lf' 'GPRINT:cacheIpEntries:LAST:Cur %lf\l' > /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_ipreqs_$int.png --start $start --vertical-label req/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid IP Requests"  DEF:cacheIpRequests=squid.rrd:cacheIpRequests:AVERAGE DEF:cacheIpHits=squid.rrd:cacheIpHits:AVERAGE DEF:cacheIpNegativeHits=squid.rrd:cacheIpNegativeHits:AVERAGE 'LINE1:cacheIpRequests#0000FF:requests' 'GPRINT:cacheIpRequests:AVERAGE:Avg %lf' 'GPRINT:cacheIpRequests:LAST:Cur %lf\l' 'LINE1:cacheIpHits#00FF00:hits    ' 'GPRINT:cacheIpHits:AVERAGE:Avg %lf' 'GPRINT:cacheIpHits:LAST:Cur %lf\l' 'LINE1:cacheIpNegativeHits#FF0000:neg hits' 'GPRINT:cacheIpNegativeHits:AVERAGE:Avg %lf' 'GPRINT:cacheIpNegativeHits:LAST:Cur %lf\l'> /dev/null

/usr/local/bin/rrdtool graph $HTMLDIR/squid_dnsreqs_$int.png --start $start --vertical-label req/s --width 700 --step 300 --height 185 --imgformat PNG --title="Squid DNS Requests"  DEF:cacheDnsRequests=squid.rrd:cacheDnsRequests:AVERAGE DEF:cacheDnsReplies=squid.rrd:cacheDnsReplies:AVERAGE 'LINE1:cacheDnsRequests#0000FF:requests' 'GPRINT:cacheDnsRequests:AVERAGE:Avg %lf' 'GPRINT:cacheDnsRequests:LAST:Cur %lf\l' 'LINE1:cacheDnsReplies#00FF00:replies ' 'GPRINT:cacheDnsReplies:AVERAGE:Avg %lf' 'GPRINT:cacheDnsReplies:LAST:Cur %lf\l' > /dev/null

