#! /usr/bin/perl # # # use RRDs; use GDBM_File; $rrddir='/home/wleiden/stats/rrd'; $ddir="$rrddir/data"; $rrdcgidir="/home/wleiden/stats/rrd/cgi"; $rrdimg='/home/wleiden/stats/rrd/img'; $genesis='/home/wleiden/svn/genesis'; $AOfile="$rrddir/areas.order"; $overall_cgi_file="$rrdcgidir/proxies.cgi"; $heartbeat=700; $com='public'; $snmpget="/usr/local/bin/snmpget -m all -c $com"; $snmpwalk="/usr/local/bin/snmpwalk -m all -c $com"; $self=$0; $comment="\tCOMMENT:\" Min: Max: Avg: Current:\"\\n"; # blauw paars dgroen groen rose geel cyaan oranje rood #@COLORS=('0088FF','FF00F0','008000','00FF00','FFC0F8','80FFFF','E0E080','FF8000','FF0000'); @COLORS=('0000FF','0099FF','00FFCC','00FF33','CC9900','FFFF00','FF6600','FF0033','FF00CC','9900FF', '0033CC','00CCCC','00CC33','66CC00','66FF00','CC0000','CC0099','6600CC', '3366FF','33FFFF','33FF66','99FF33','FFCC33','FF3333','FF33CC','9933FF' ); $RRA=sprintf<&1`;if ($alive!~/alive/) {print "$proxy offline. Skipped.\n";next;} if ($proxy!~/tango|proxy3/) {$doit="ssh root@$proxy '$snmpwalk -m all -C c -p 3401 localhost enterprises'";} else { {$doit="$snmpwalk -p 3401 $proxy enterprises";}} $rrdimgdir="/home/wleiden/stats/rrd/img/$node"; if (! -d $rrdimgdir) {mkdir($rrdimgdir,0777) || die;} if ($DEBUG) {print "Doing: $proxy: $doit\n";} open(PROXY,"$doit 2>&1|") || die; while () { s/(Counter|Gauge)32://; #print $_; if (/Timeout: No Response from/) {$timeout=$_;last;} if (s/^enterprises.nlanr.squid.cachePerf.cacheSysPerf.//) { if (/^([^\.]+)\.\d+\s+=\s+(.*)/) {$PERF{$1}=$2;} } elsif (s/^enterprises.nlanr.squid.cachePerf.cacheProtoStats.cacheProtoAggregateStats.//) { if (/^([^\.]+)\.\d+\s+=\s+(.*)/) {$AGGSTATS{$1}=$2;} }elsif (s/^enterprises.nlanr.squid.cachePerf.cacheProtoStats.cacheMedianSvcTable.cacheMedianSvcEntry.//) { if (/^([^\.]+)\.5\s+=\s+(.*)/) {$MEDIAN5{$1}=$2;} }elsif (s/^enterprises.nlanr.squid.cacheSystem.//) { if (/^([^\.]+)\.\d+\s+=\s+(.*)/) {$SYS{$1}=$2;} } elsif (s/^enterprises.nlanr.squid.cacheMesh.cachePeerTable.cachePeerEntry.//) { if (/^([^\.]+)\.(\d+\.\d+\.\d+\.\d+)\s+=\s+(.*)/) { $name=$1; $ip=$2; $value=$3; # print "PEER: $name [$ip] = $value\n"; } } elsif (s/^enterprises.nlanr.squid.cacheMesh.cacheClientTable.cacheClientEntry.//) { if (/^([^\.]+)\.(\d+\.\d+\.\d+\.\d+)\s+=\s+(.*)/) { $name=$1; $ip=$2; $value=$3; $AO=0; $area=get_area($ip); $AO=area_order($area); if ($name=~/cacheClientAddr/) { $CClients{$AO}++; # print "A1:$AO:$area:$ip:\n"; next; } # print "TEST: $name [$ip]\n"; $key="$name:$ip"; if (exists ($H{$key})) { $last=$H{$key}; $diff=$value-$last; # print "CLIENT: $name [$ip] = $diff [$value]\n"; if ($diff ne 0) { if ($elapsed > 0) {$diff=$diff/$elapsed;} $CLIENTS{$ip}++; if ($name=~/cacheClientHttpRequests/) {$CHttpRequests{$AO}+=$diff;} elsif ($name=~/cacheClientHttpKb/) {$CHttpKb{$AO}+=$diff * 1024;} elsif ($name=~/cacheClientHttpHits/) {$CHttpHits{$AO}+=$diff;} elsif ($name=~/cacheClientHttpHitKb/i) {$CHttpHitKb{$AO}+=$diff * 1024;} elsif ($name=~/cacheClientIcpRequests/) {$CIcpRequests{$AO}+=$diff;} elsif ($name=~/cacheClientIcpKb/) {$CIcpKb{$AO}+=$diff * 1024;} elsif ($name=~/cacheClientIcpHits/) {$CIcpHits{$AO}+=$diff;} } } $H{$key}=$value; } } #elsif ($DEBUG) {print $_;} } close(PROXY); foreach $ip (keys %CLIENTS) { $area=get_area($ip); $AO=area_order($area); $CAClients{$AO}++; } if ($timeout) {print STDERR "TIMEOUT: $timeout";next;} { local($tpl,$data)=(); print "Parsing data received from: $proxy\n"; rradd($file,ServerRequests,$AGGSTATS{cacheClientServerRequests}); rradd($file,ServerErrors,$AGGSTATS{cacheServerErrors}); rradd($file,HttpRequests,$AGGSTATS{cacheClientHttpRequests}); rradd($file,HttpHits,$AGGSTATS{cacheHttpHits}); rradd($file,HttpErrors,$AGGSTATS{cacheHttpErrors}); if ($AGGSTATS{cacheCurrentSwapSize}=~/(\d+)$/) {rradd($file,CurrentSwapSize,$1);} if ($AGGSTATS{cacheClients}=~/(\d+)$/) {rradd($file,cacheClients,$1);} rradd($file,HttpInKb,$AGGSTATS{cacheHttpInKb} * 1024); rradd($file,HttpOutKb,$AGGSTATS{cacheHttpOutKb} * 1024); rradd($file,ServerInKb,$AGGSTATS{cacheServerInKb} * 1024); rradd($file,ServerOutKb,$AGGSTATS{cacheServerOutKb} * 1024); rradd($file,IcpPktsRecv,$AGGSTATS{cacheIcpPktsRecv} * 1024); rradd($file,IcpPktsSent,$AGGSTATS{cacheIcpPktsSent} * 1024); rradd($file,HttpAllSvcTime, $MEDIAN5{cacheHttpAllSvcTime} /1000); rradd($file,DnsSvcTime, $MEDIAN5{cacheDnsSvcTime} /1000); rradd($file,IcpQuerySvcTime, $MEDIAN5{cacheIcpQuerySvcTime} /1000); rradd($file,HttpHitSvcTime, $MEDIAN5{cacheHttpHitSvcTime} /1000); rradd($file,HttpMissSvcTime, $MEDIAN5{cacheHttpMissSvcTime} /1000); rradd($file,HttpNmSvcTime, $MEDIAN5{cacheHttpNmSvcTime} /1000); rradd($file,CpuUsage, $PERF{cacheCpuUsage}); rradd($file,MemUsage, $PERF{cacheMemUsage} * 1024); rradd($file,SysStorage,$SYS{cacheSysStorage} * 1024); if ($SYS{cacheUptime}=~/\((\d+)\)/) {rradd($file,cacheUptime,$1/(100*86400));} if ($PERF{cacheNumObjCount}=~/(\d+)$/) {rradd($file,NumObjCount,$1);} if ($DEBUG) {print "\n\n";} foreach $AO (keys %CClients) { rradd($clientfile,"Clients_$AO", $CClients{$AO}); rradd($clientfile,"AClients_$AO", $CAClients{$AO}); rradd($clientfile,"HttpRequests_$AO", $CHttpRequests{$AO}); rradd($clientfile,"HttpKb_$AO", $CHttpKb{$AO}); rradd($clientfile,"HttpHits_$AO", $CHttpHits{$AO}); rradd($clientfile,"HttpHitKb_$AO", $CHttpHitKb{$AO}); rradd($clientfile,"IcpRequests_$AO", $CIcpRequests{$AO}); rradd($clientfile,"IcpKb_$AO", $CIcpKb{$AO}); rradd($clientfile,"IcpHits_$AO", $CIcpHits{$AO}); #print "\nAO:$AO:$CHttpRequests{$AO}:$CHttpKb{$AO}:$CHttpHits{$AO}:$CHttpHitKb{$AO}:$CIcpRequests{$AO}:$CIcpKb{$AO}:$CIcpHits{$AO}:\n" } if ($DEBUG) {print "\n\n";} rrupdate($file); rrupdate($peerfile); rrupdate($clientfile); } untie (%H); } if ($do_overall_cgi) { if ($DEBUG) {print "Doing overall CGI.\n";} $client_counter=0;$proxy_counter=4;$proxy_STACK='AREA'; local($proxycolor)="#" . $COLORS[$proxy_counter+=2]; foreach $proxy (@proxies) { $ocgi_pclientss{$proxy}="\tCDEF:AClients_${proxy}=0" } foreach $area (sort {mysort($a,$b)} keys %AO) { $order=$AO{$area}; $desc=$DESC{$area};if ($desc eq '') {$desc="$area";} $color="#" . $COLORS[$client_counter++];if ($client_counter > $#COLORS) {$client_counter=0;} $ocgi_aaclients2="\tCDEF:Clients_${order}=0"; $ocgi_aclients2="\tCDEF:AClients_${order}=0"; $ocgi_aclients1=$ocgi_aaclients1=''; $ocgi_aCTraf2="\tCDEF:CTraf_${order}=0"; $ocgi_aTraf2="\tCDEF:Traf_${order}=0"; $ocgi_aCTraf1=$ocgi_aTraf1=''; foreach $proxy (@proxies) { local($clientfile)="$ddir/$proxy/squid-client.rrd"; $p="${proxy}_Cl_${order}"; $ocgi_aaclients.="\tDEF:$p=$clientfile:Clients_$order:AVERAGE\n"; $ocgi_aaclients1.="\tCDEF:U$p=$p,UN,0,$p,IF\n"; $ocgi_aaclients2.=",U$p,+"; $p="${proxy}_ACl_${order}"; $ocgi_aclients.="\tDEF:$p=$clientfile:AClients_$order:AVERAGE\n"; $ocgi_aclients1.="\tCDEF:U$p=$p,UN,0,$p,IF\n"; $ocgi_aclients2.=",U$p,+"; $ocgi_pclients.="\tDEF:$p=$clientfile:AClients_$order:AVERAGE\n"; $ocgi_pclients.="\tCDEF:U$p=$p,UN,0,$p,IF\n"; $ocgi_pclientss{$proxy}.=",U$p,+"; $p="${proxy}_CT_${order}"; $ocgi_aCTraf.="\tDEF:$p=$clientfile:HttpKb_$order:AVERAGE\n"; $ocgi_aCTraf1.="\tCDEF:U$p=$p,UN,0,$p,IF\n"; $ocgi_aCTraf2.=",U$p,+"; $p="${proxy}_T_${order}"; $ocgi_aTraf.="\tDEF:$p=$clientfile:Traf_$order:AVERAGE\n"; $ocgi_aTraf1.="\tCDEF:U$p=$p,UN,0,$p,IF\n"; $ocgi_aTraf2.=",U$p,+"; } $ocgi_aaclients.="${ocgi_aaclients1}${ocgi_aaclients2}\n"; $ocgi_aclients.="${ocgi_aclients1}${ocgi_aclients2}\n"; $ocgi_aCTraf.="${ocgi_aCTraf1}${ocgi_aCTraf2}\n"; $ocgi_aTraf.="${ocgi_aTraf1}${ocgi_aTraf2}\n"; $ocgi_aaclients.=addData("Clients_${order}",$color,$desc,$proxy_STACK,""); $ocgi_aaclientsS.="UClients_${order},+,"; $ocgi_aclients.=addData("AClients_${order}",$color,$desc,$proxy_STACK,""); $ocgi_aclientsS.="UAClients_${order},+,"; $ocgi_aCTraf.=addData("CTraf_${order}",$color,$desc,$proxy_STACK,"%sB/s"); $ocgi_aCTrafS.="UCTraf_${order},+,"; $ocgi_aTraf.=addData("Traf_${order}",$color,$desc,$proxy_STACK,"%sB/s"); $ocgi_aTrafS.="UTraf_${order},+,"; $proxy_STACK='STACK'; } $proxy_STACK='AREA';$proxy_counter=4; foreach $proxy (@proxies) { local($proxycolor)="#" . $COLORS[$proxy_counter+=2]; $ocgi_pclients.= $ocgi_pclientss{$proxy} . "\n"; $ocgi_pclients.=addData("AClients_${proxy}",$proxycolor,$proxy,$proxy_STACK,""); $ocgi_pclientsS.="UAClients_${proxy},+,"; $proxy_STACK='STACK'; } $color="#000000"; $ocgi_requestsS=~s/,$//; $ocgi_requests.="$ocgi_requestsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $ocgi_clientsS=~s/,$//; $ocgi_clients.="$ocgi_clientsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $ocgi_aclientsS=~s/,$//; $ocgi_aclients.="$ocgi_aclientsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $ocgi_pclientsS=~s/,$//; $ocgi_pclients.="$ocgi_pclientsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $ocgi_aaclientsS=~s/,$//; $ocgi_aaclients.="$ocgi_aaclientsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $ocgi_CTraf.="${ocgi_CTraf2}\n${ocgi_CTraf3}\n"; $ocgi_Traf.= "${ocgi_Traf2}\n${ocgi_Traf3}\n"; $ocgi_DSL_Traf.= "${ocgi_DSL_Traf2}\n${ocgi_DSL_Traf3}\n"; $ocgi_CTrafSi=~s/,$//; $ocgi_CTrafSo=~s/,$//; $ocgi_CTraf.="$ocgi_CTrafSi\n$ocgi_CTrafSo\n" . addData("TOTALi",$color,"totaal in",'LINE1',"%sB/s") . addData("TOTALo",$color,"totaal out",'LINE1',"%sB/s"); $ocgi_TrafSi=~s/,$//; $ocgi_TrafSo=~s/,$//; $ocgi_Traf.="$ocgi_TrafSi\n$ocgi_TrafSo\n" . addData("TOTALi",$color,"totaal in",'LINE1',"%sB/s") . addData("TOTALo",$color,"totaal out",'LINE1',"%sB/s"); $ocgi_DSL_TrafSi=~s/,$//; $ocgi_DSL_TrafSo=~s/,$//; $ocgi_DSL_Traf.="$ocgi_DSL_TrafSi\n$ocgi_DSL_TrafSo\n" . addData("TOTALi",$color,"totaal in",'LINE1',"%sB/s") . addData("TOTALo",$color,"totaal out",'LINE1',"%sB/s"); $ocgi_aTrafS=~s/,$//; $ocgi_aTraf.="$ocgi_aTrafS\n" . addData("TOTAL",$color,"totaal",'LINE1',"%sB/s"); $ocgi_aCTrafS=~s/,$//; $ocgi_aCTraf.="$ocgi_aCTrafS\n" . addData("TOTAL",$color,"totaal",'LINE1',"%sB/s"); $ocgi_requests.=">\n\n"; $ocgi_clients.=">\n\n"; $ocgi_aclients.=">\n\n"; $ocgi_pclients.=">\n\n"; $ocgi_aaclients.=">\n\n"; $ocgi_aCTraf.=">\n\n"; $ocgi_aTraf.=">\n\n"; $ocgi_CTraf.=">\n\n"; $ocgi_Traf.= ">\n\n"; $ocgi_DSL_Traf.= ">\n\n"; print OCGI< Individual proxies: EOC foreach $proxy (@proxies) { print OCGI ">$proxy\n"; } print OCGI "\n\n"; close(OCGI); chmod(0755,"$overall_cgi_file.$$"); unlink($overall_cgi_file); rename("$overall_cgi_file.$$",$overall_cgi_file); } sub check_overall_cgi { local($age); if (-e $overall_cgi_file) { $age= (-M $self) - (-M $overall_cgi_file) ; if ($age > 0) {return(0);} } if ($DEBUG) {print "Creating new $overall_cgi_file\n";} open (OCGI,">$overall_cgi_file.$$\n") || die "Could not create: $overall_cgf_file\n"; print OCGI init_cgi(); $ocgi_requests=RRD_init("All Requests",'overall-squid-requests',"requests/s",100,'',"-${heartbeat}s");; $ocgi_clients=RRD_init("All Clients per proxy",'overall-squid-clients',"clients",100,'',"-${heartbeat}s");; $ocgi_clients.=" --lower-limit 0 --rigid\n"; $ocgi_aaclients=RRD_init("All Clients per Area",'overall-squid-aaclients',"clients",250,'',"-${heartbeat}s");; $ocgi_aaclients.=" --lower-limit 0 --rigid\n"; $ocgi_aclients=RRD_init("All Active Clients per Area",'overall-squid-aclients',"clients",250,'',"-${heartbeat}s");; $ocgi_aclients.=" --lower-limit 0 --rigid\n"; $ocgi_pclients=RRD_init("All Active Clients per Proxy",'overall-squid-pclients',"clients",100,'',"-${heartbeat}s");; $ocgi_pclients.=" --lower-limit 0 --rigid\n"; $ocgi_aHttpKb=RRD_init("All http traffic per Area",'overall-squid-ahttpkb',"",250,'',"-${heartbeat}s");; $ocgi_CTraf=RRD_init("All Client Traffic per proxy",'overall-squid-CTraffic',"",100,'',"-${heartbeat}s");; $ocgi_Traf=RRD_init("All Server Traffic per proxy",'overall-squid-traffic',"",100,'',"-${heartbeat}s");; $ocgi_aCTraf=RRD_init("Client Traffic per Area",'overall-squid-aCTraffic',"",250,'',"-${heartbeat}s");; $ocgi_aTraf=RRD_init("Server Traffic per Area",'overall-squid-atraffic',"",250,'',"-${heartbeat}s");; $ocgi_DSL_Traf=RRD_init("All DSL Traffic per proxy",'overall-dsl-traffic',"",100,'',"-${heartbeat}s");; $ocgi_clientsS="\tCDEF:TOTAL=0,"; $ocgi_requestsS="\tCDEF:TOTAL=0,"; $ocgi_aclientsS="\tCDEF:TOTAL=0,"; $ocgi_pclientsS="\tCDEF:TOTAL=0,"; $ocgi_aaclientsS="\tCDEF:TOTAL=0,"; $ocgi_CTrafSi="\tCDEF:TOTALi=0,"; $ocgi_CTrafSo="\tCDEF:TOTALo=0,"; $ocgi_TrafSi="\tCDEF:TOTALi=0,"; $ocgi_TrafSo="\tCDEF:TOTALo=0,"; $ocgi_DSL_TrafSi="\tCDEF:TOTALi=0,"; $ocgi_DSL_TrafSo="\tCDEF:TOTALo=0,"; $ocgi_aCTrafS="\tCDEF:TOTAL=0,"; $proxy_counter=4;$proxy_STACK='AREA'; return(1); } sub rradd { local($file,$t,$d)=@_; if (($d ne '') && ($t ne '')) { $d=sprintf("%f",$d); $TPL{$file}.="$t:"; $DATA{$file}.="$d:"; if ($DEBUG) {print "[$t=$d]:";} } } sub check_rrd_proxyfile { local($file,$timeout)=@_; if ((-e $file) && ($ARGV[1] ne 'WISDATA')) {return;} $DS=sprintf<.png -a PNG -v '$Yunit' $heigth $args --alt-autoscale-max --imginfo '' --lazy --start --end $end --title="$Desc $proxy" $comment EOS } sub init_cgi { local($now);$now=localtime(time()); return sprintf< <RRD::CV RRD_NODE>Squid proxy statistieken $proxy <RRD::CV RRD_START>

Squid proxy statistieken $proxy

Start graph at:

-1, -4, -8. -24 hours. -4 days. -7 days. -1 month. -6 months. -1 year.
EOS } sub rrupdate { local($file)=@_; local($tpl,$data); if ( ! -e $file) { print "File does not exist: $file\n"; return; } $tpl=$TPL{$file};delete($TPL{$file}); $data=$DATA{$file};delete($DATA{$file}); $tpl=~s/:$//; $data=~s/:$//; #print "Filing: $file:[$tpl]:[$data]\n"; if (($data ne '') && ($tpl ne '')) { $data="N:$data"; # if ($DEBUG) {print "DRRU: $file $tpl=$data\n";} RRDs::update ($file,"--template",$tpl,$data); $ERR=RRDs::error; if ($ERR) {print STDERR "ERROR while updating $file: $ERR\n"} } if (! $DEBUG) {sleep(1);} } sub check_cgi { local($proxy,$datafile,$clientdatafile,$peerdatafile)=@_; local($dir)="$rrdcgidir/$proxy"; local($file)="$dir/proxy.cgi"; local($proxycolor)="#" . $COLORS[$proxy_counter+=2]; if (! -d $dir) {mkdir($dir,0777) || die "Could not create dir: $dir";} if ($overall_cgi_file eq 0) {return();} if ($DEBUG) {print "Creating $file [$datafile]\n";} open (CGI,">$file.$$\n") || die "Could not create: $file\n"; print CGI init_cgi(); $client_counter=0; $rrd_clients=RRD_init("Total Clients per Area",'squid-clients',"clients",250); $rrd_clients.=" --lower-limit 0 --rigid\n"; $rrd_aclients=RRD_init("Active Clients last 5 min. per Area",'squid-aclients',"clients",250); $rrd_aclients.=" --lower-limit 0 --rigid\n"; $rrd_aRequests=RRD_init("Requests per Area",'squid-arequests',"requests/s",250); $rrd_aHttpKb=RRD_init("http traffic per Area",'squid-ahttptraf',"",250); $STACK='AREA'; $rrd_aclientsS="\tCDEF:TOTAL=0,"; $rrd_aRequestsS="\tCDEF:TOTAL=0,"; $rrd_aHttpKbS="\tCDEF:TOTAL=0,"; foreach $area (sort {mysort($a,$b)} keys %AO) { $order=$AO{$area}; $desc=$DESC{$area};if ($desc eq '') {$desc="$area";} $color="#" . $COLORS[$client_counter++];if ($client_counter > $#COLORS) {$client_counter=0;} $rrd_clients.="\tDEF:Clients_${order}=$clientdatafile:Clients_$order:AVERAGE\n"; $rrd_clients .=addData("Clients_${order}",$color,$desc,$STACK); $rrd_aclients.="\tDEF:AClients_${order}=$clientdatafile:AClients_$order:AVERAGE\n"; $rrd_aclients.=addData("AClients_${order}",$color,$desc,$STACK); $rrd_aclientsS.="UAClients_${order},+,"; $rrd_aRequests.="\tDEF:HttpRequests_${order}=$clientdatafile:HttpRequests_${order}:AVERAGE\n"; $rrd_aRequests.=addData("HttpRequests_${order}",$color,$desc,$STACK); $rrd_aRequestsS.="UHttpRequests_${order},+,"; $rrd_aHttpKb.="\tDEF:HttpKb_${order}=$clientdatafile:HttpKb_${order}:AVERAGE\n"; $rrd_aHttpKb.=addData("HttpKb_${order}",$color,$desc,$STACK,'%sB/s'); $rrd_aHttpKbS.="UHttpKb_${order},+,"; #print "AO:$order:$area:$desc\n"; $STACK='STACK'; } $rrd_clients.="\tDEF:cacheClients=$datafile:cacheClients:AVERAGE\n"; $color="#000000"; $rrd_clients.=addData("cacheClients",$color,"totaal",'LINE1'); $rrd_aclientsS=~s/,$//; $rrd_aclients.="$rrd_aclientsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $rrd_aRequestsS=~s/,$//; $rrd_aRequests.="$rrd_aRequestsS\n" . addData("TOTAL",$color,"totaal",'LINE1'); $rrd_aHttpKbS=~s/,$//; $rrd_aHttpKb.="$rrd_aHttpKbS\n" . addData("TOTAL",$color,"totaal",'LINE1','%sB/s'); $ocgi_clients.="\tDEF:cacheClients_${proxy}=${datafile}:cacheClients:AVERAGE\n"; $ocgi_clients.=addData("cacheClients_${proxy}",$proxycolor,$proxy,$proxy_STACK); $ocgi_clientsS.="UcacheClients_${proxy},+,"; $rrd_clients.=">\n\n"; $rrd_aclients.=">\n\n"; $rrd_aRequests.=">\n\n"; $rrd_aHttpKb.=">\n\n"; $rrd_cpu=RRD_init("CPU Usage",'squid-cpu',"%",100); $rrd_cpu.=" --lower-limit 0 --rigid\n"; $rrd_cpu.="\tDEF:CpuUsage=$datafile:CpuUsage:AVERAGE\n"; $rrd_cpu.=addData("CpuUsage","#00FF00","cpuload",'AREA',"%%"); $rrd_cpu.=">\n\n"; $rrd_mem=RRD_init("Mem Usage",'squid-mem',"Bytes",100); $rrd_mem.="\tDEF:MemUsage=$datafile:MemUsage:AVERAGE\n"; $rrd_mem.=addData("MemUsage","#00FF00","memory",'AREA',"%sB"); $rrd_mem.=">\n\n"; $rrd_stor=RRD_init("Storage Usage",'squid-stor',"Bytes",100); $rrd_stor.="\tDEF:SysStorage=$datafile:SysStorage:AVERAGE\n"; $rrd_stor.=addData("SysStorage","#00FF00","storage",'AREA',"%sB"); $rrd_stor.=">\n\n"; $rrd_uptime=RRD_init("Uptime",'squid-uptime',"days",100); $rrd_uptime.="\tDEF:cacheUptime=$datafile:cacheUptime:AVERAGE\n"; $rrd_uptime.=addData("cacheUptime","#00FF00","uptime",'AREA',"days"); $rrd_uptime.=">\n\n"; $rrd_objs=RRD_init("Cache Objects",'squid-objs',"objects",100); $rrd_objs.="\tDEF:NumObjCount=$datafile:NumObjCount:AVERAGE\n"; $rrd_objs.=addData("NumObjCount","#00FF00","Objects",'AREA',"%s"); $rrd_objs.=">\n\n"; $rrd_Requests=RRD_init("Requests",'squid-requests',"requests/s",100); $rrd_Requests.="\tDEF:HttpRequests=$datafile:HttpRequests:AVERAGE\n"; $rrd_Requests.=addData("HttpRequests","#00FF00","http",'AREA',"req/s"); $rrd_Requests.=">\n\n"; $ocgi_requests.="\tDEF:HttpRequests_$proxy=$datafile:HttpRequests:AVERAGE\n"; $ocgi_requests.=addData("HttpRequests_$proxy",$proxycolor,"$proxy",$proxy_STACK,""); $ocgi_requestsS.="UHttpRequests_$proxy,+,"; $rrd_Swaps=RRD_init("Swap size",'squid-swaps',"Bytes",100); $rrd_Swaps.="\tDEF:CurrentSwapSize=$datafile:CurrentSwapSize:AVERAGE\n"; $rrd_Swaps.=addData("CurrentSwapSize","#00FF00","SwapSize",'AREA',"%sB"); $rrd_Swaps.=">\n\n"; $rrd_Ipkts=RRD_init("ICP Packets",'squid-ipkts','Packets/s',100,'--logarithmic'); $rrd_Ipkts.="\tDEF:InPkts=$datafile:IcpPktsRecv:AVERAGE\n"; $rrd_Ipkts.="\tDEF:OutPkts=$datafile:IcpPktsSent:AVERAGE\n"; $rrd_Ipkts.="\tCDEF:NOutPkts=0,OutPkts,-\n"; $rrd_Ipkts.=addData("InPkts","#00FF00","In",'AREA',"%spk/s"); $rrd_Ipkts.=addData("NOutPkts","#0000FF","Out",'AREA',"%spk/s"); $rrd_Ipkts.=">\n\n"; $rrd_Traf=$rrd_Traf1=$rrd_Traf2=$rrd_Traf3=$rrd_Traf4=''; $rrd_Traf.=RRD_init("Server Traffic",'squid-traffic',"",100,'--logarithmic'); $rrd_Traf.="\tDEF:InKb=$datafile:ServerInKb:AVERAGE\n"; $rrd_Traf.="\tDEF:OutKb=$datafile:ServerOutKb:AVERAGE\n"; $rrd_Traf.="\tCDEF:NOutKb=0,OutKb,-\n"; $rrd_Traf.=addData("InKb","#00FF00","In",'AREA',"%sB/s"); $rrd_Traf.=addData("NOutKb","#0000FF","Out",'AREA',"%sB/s"); $rrd_Traf.="\tCDEF:Null=InKb,UN,0,*\n"; $rrd_Traf.="\tLINE3:Null#000000:\n"; $rrd_Traf.=">\n\n"; $ocgi_Traf.="\tDEF:InKb_$proxy=$datafile:ServerInKb:AVERAGE\n"; $ocgi_Traf.="\tDEF:OutKb_$proxy=$datafile:ServerOutKb:AVERAGE\n"; $ocgi_Traf.="\tCDEF:NOutKb_$proxy=0,OutKb_${proxy},-\n"; $ocgi_Traf.=addData("InKb_${proxy}",$proxycolor,"$proxy In",$proxy_STACK,"%sB/s"); $ocgi_Traf2.=addData("NOutKb_${proxy}",$proxycolor,"$proxy Out",$proxy_STACK,"%sB/s"); $ocgi_Traf3="\tCDEF:Null=NOutKb_${proxy},UN,0,*\n"; $ocgi_Traf3.="\tLINE3:Null#000000:\n"; $ocgi_TrafSi.="UInKb_${proxy},+,"; $ocgi_TrafSo.="UNOutKb_${proxy},+,"; if ($proxy!~/tango/i) { $traffile="$ddir/$proxy/int-xl0.rrd"; $ocgi_DSL_Traf.="\tDEF:InKb_$proxy=$traffile:bytes_in:AVERAGE\n"; $ocgi_DSL_Traf.="\tDEF:OutKb_$proxy=$traffile:bytes_out:AVERAGE\n"; $ocgi_DSL_Traf.="\tCDEF:NOutKb_$proxy=0,OutKb_${proxy},-\n"; $ocgi_DSL_Traf.=addData("InKb_${proxy}",$proxycolor,"$proxy In",$proxy_STACK2,"%sB/s"); $ocgi_DSL_Traf2.=addData("NOutKb_${proxy}",$proxycolor,"$proxy Out",$proxy_STACK2,"%sB/s"); $ocgi_DSL_Traf3="\tCDEF:Null=NOutKb_${proxy},UN,0,*\n"; $ocgi_DSL_Traf3.="\tLINE3:Null#000000:\n"; $ocgi_DSL_TrafSi.="UInKb_${proxy},+,"; $ocgi_DSL_TrafSo.="UNOutKb_${proxy},+,"; $proxy_STACK2='STACK'; } $rrd_CTraf=RRD_init("Client Traffic",'squid-Ctraffic',"", 100,'--logarithmic'); $rrd_CTraf.="\tDEF:InKb=$datafile:HttpInKb:AVERAGE\n"; $rrd_CTraf.="\tDEF:OutKb=$datafile:HttpOutKb:AVERAGE\n"; $rrd_CTraf.="\tCDEF:NInKb=0,InKb,-\n"; $rrd_CTraf.=addData("NInKb","#0000FF","In",'AREA',"%sB/s"); $rrd_CTraf.=addData("OutKb","#00FF00","Out",'AREA',"%sB/s"); $rrd_CTraf.="\tCDEF:Null=NInKb,UN,0,*\n"; $rrd_CTraf.="\tLINE3:Null#000000:\n"; $rrd_CTraf.=">\n\n"; $ocgi_CTraf.="\tDEF:InKb_$proxy=$datafile:HttpInKb:AVERAGE\n"; $ocgi_CTraf.="\tDEF:OutKb_$proxy=$datafile:HttpOutKb:AVERAGE\n"; $ocgi_CTraf.="\tCDEF:NInKb_$proxy=0,InKb_${proxy},-\n"; $ocgi_CTraf.=addData("NInKb_${proxy}",$proxycolor,"$proxy In",$proxy_STACK,"%sB/s"); $ocgi_CTraf.=addData("OutKb_${proxy}",$proxycolor,"$proxy Out",$proxy_STACK,"%sB/s"); $ocgi_CTraf3="\tCDEF:Null=NInKb_${proxy},UN,0,*\n"; $ocgi_CTraf3.="\tLINE3:Null#000000:\n"; $ocgi_CTrafSi.="UNInKb_${proxy},+,"; $ocgi_CTrafSo.="UOutKb_${proxy},+,"; $srvc=0; $rrd_srv_time=RRD_init("Service Time",'squid-srvtime',"seconds",100); $rrd_srv_time.="\tDEF:HttpAllSvcTime=$datafile:HttpAllSvcTime:AVERAGE\n"; $rrd_srv_time.="\tDEF:DnsSvcTime=$datafile:DnsSvcTime:AVERAGE\n"; $rrd_srv_time.="\tDEF:IcpQuerySvcTime=$datafile:IcpQuerySvcTime:AVERAGE\n"; $rrd_srv_time.="\tDEF:HttpHitSvcTime=$datafile:HttpHitSvcTime:AVERAGE\n"; $rrd_srv_time.="\tDEF:HttpMissSvcTime=$datafile:HttpMissSvcTime:AVERAGE\n"; $rrd_srv_time.="\tDEF:HttpNmSvcTime=$datafile:HttpNmSvcTime:AVERAGE\n"; $rrd_srv_time.=addData("HttpAllSvcTime","#$COLORS[$srvc++]","http",'AREA',"%ss"); $rrd_srv_time.=addData("DnsSvcTime","#$COLORS[$srvc++]","dns",'LINE3',"%ss"); $rrd_srv_time.=addData("IcpQuerySvcTime","#$COLORS[$srvc++]","icp",'LINE3',"%ss"); $rrd_srv_time.=addData("HttpHitSvcTime","#$COLORS[$srvc++]","http hit",'LINE3',"%ss"); $rrd_srv_time.=addData("HttpMissSvcTime","#$COLORS[$srvc++]","http miss",'LINE3',"%ss"); $rrd_srv_time.=addData("HttpNmSvcTime","#$COLORS[$srvc++]","http not modified",'LINE3',"%ss"); $rrd_srv_time.=">\n\n"; print CGI <

$rrd_Traf\n $rrd_srv_time\n $rrd_Ipkts\n $rrd_objs\n $rrd_stor\n $rrd_cpu\n $rrd_mem\n $rrd_Swaps\n $rrd_uptime\n EOC close(CGI); chmod(0755,"$file.$$"); unlink($file); rename("$file.$$",$file); $proxy_STACK='STACK'; } sub mysort { local($a,$b)=@_; local($A)=$AO{$a};if ($a eq -1) {$A=99999;} local($B)=$AO{$b};if ($b eq -1) {$B=99998;} #print "AO{$a}=$A <=> AO{$b}=$B\n"; return($AO{$a} <=> $AO{$b}); } sub get_area { local($IP)=@_; local($range); local($ip,$netmask,$broadcast,$network,$width); local($a,$b,$c,$d)=split(/\./,$IP); local($II)=($a<<24)+($b<<16)+($c<<8)+$d; local($ii,$ip,$nm,$I2); # for ($i=0;$i<=$maxareas;$i++) # { # $ii=$II[$i]; # $nm=$NM[$i]; # $I2=$II & $nm; ##$ospfd.=sprintf "i=$i\t $RANGE[$i]\t ii=$ii\t nm=$nm\t I2=$I2 $II $IP $a,$b,$c,$d\n"; # if ($I2 == $ii) {return($AREA[$i]);} # } # return(12345); $area=-1; if ($a eq 172) { if (($b >= 16) && ($b < 32)) { if ($b eq 16) {$area=0;} elsif ($c < 128) {$area=($b * 10)} else {$area=(1+($b*10));} } } if ($area > 255) {$area/=10;} return($area); } $max_area_order=1; sub read_area_order { if ($DEBUG) {print "Reading file $AOfile\n";} if (-e $AOfile) { open(AO,$AOfile) || die "Could not open file: $AOfile\n"; while () { $area=int($_); $AO{$area}=$max_area_order++; } close(AO); } # $AO{}=-1; } sub area_order { local($area)=@_;$area=int($area); if (! exists($AO{$area})) { open(AO,">>$AOfile") || die "Coult not create: $AOfile\n"; print AO "$area\n"; close(AO); $AO{$area}=$max_area_order++; } return($AO{$area}); } sub read_areas { if ($DEBUG) {print "Reading $genesis/areas.conf\n";} $maxareas=0; open(AC,"$genesis/areas.conf") || die; while () { chomp(); s/#.*$//; if (! $_) {next;} ($area,$range,$desc)=/(\S+)\s+(\S+)\s+(.*)/; $AREA[$maxareas]=$area; $RANGE[$maxareas]=$range; $DESC[$maxareas]=$desc;$DESC{$area}=$desc; #print "AREA:$area=$range=$desc\n"; ($ip,$width)=split(/\//,$range); ($a,$b,$c,$d)=split(/\./,$ip); $ii=($a<<24)+($b<<16)+($c<<8)+$d; if ($width eq 32) {$nm=0xffffffff;} else {$nm=0xffffffff-1<<(31-$width);} $II[$maxareas]=$ii; $NM[$maxareas]=$nm; $maxareas++; } close(AC); $DESC{-1}='Other'; } sub calc_ip { local($i)=@_; local($a,$b,$c,$d); local($ip,$width)=split(/\//,$i); local($a,$b,$c,$d)=split(/\./,$ip); local($ii)=($a<<24)+($b<<16)+($c<<8)+$d; if ($width eq 32) {$nm=0xffffffff;} else {$nm=0xffffffff-1<<(31-$width);} $nw=($ii & $nm); $br=$nw | (0xffffffff & ~$nm); $netmask=itoadr($nm);; $broadcast=itoadr($br);; $network=itoadr($nw); # $i=itoadr($ii); # printf "ip=$ip|width=$width|nm=%0x|$netmask|br=%0x|$broadcast|$i|\n",$nm,$br; return($ip,$netmask,$broadcast,$network,$width); } sub itoadr { local($ip)=@_; local($a,$b,$c,$d); $a=($ip & 0xff000000) >> 24; $b=($ip & 0x00ff0000) >> 16; $c=($ip & 0x0000ff00) >> 8; $d=($ip & 0x000000ff); return("$a.$b.$c.$d"); } sub addData { local($p,$color,$pdesc,$type,$unit)=@_; if ($unit=~s/^%s//) {$unit="%s" . sprintf("%-4s",$unit);} else {$unit=sprintf("%-5s",$unit);} $pdesc=sprintf("%-18s",$pdesc); local($result)=<