#! /usr/bin/perl # # # use GDBM_File; use Socket; $genesis_dir='/home/wleiden/svn/genesis'; $svn='/usr/local/bin/svn'; $wlan_stats='/home/wleiden/svn/stats/mrtg/wlan_stats.pl'; $rrdimg='/home/wleiden/stats/rrd/img'; $rrddata='/home/wleiden/stats/rrd/data'; $heartbeat=700; $PINGNODE{"172.17.8.1"}="CNodeCope"; $PINGNODE{"172.18.8.1"}="CNodeJasper"; $PINGNODE{"172.17.136.1"}="CNodeCeTIM1"; $PINGNODE{"172.20.128.1"}="CNodeRV"; $PINGNODE{"172.19.128.1"}="CNodeUnigor"; $PINGNODE{"172.17.48.1"}="CNodeThomas"; $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< [$revision]\n";} chdir("/home/wleiden/svn/genesis/nodes/") || die "$!: /home/wleiden/svn/genesis/nodes/"; foreach $file (<*/wleiden.conf>) { $file=~s/\/wleiden\.conf//gi; #print "FILE: $file\n"; if (! grep(/^$file$/,@NODES)) { push(@NODES,$file); # if ($DEBUG) {print STDERR "Adding node $file\n";} } } unlink("$xyfile.$$"); tie %XY,'GDBM_File',"$xyfile.$$", &GDBM_WRCREAT, 0640 || die "$! $xyfile.$$\n"; $rrdindexfilename="/home/wleiden/public_html/rrdindex.html"; open (RRDINDEX,">$rrdindexfilename.$$") || die "$! $rrdindexfilename.$$\n"; #$node='CNodeCope'; foreach $node (@NODES) { if ($node=~/(demo|test|vuilnis|vpn)/) {next;} $nodez++; if ($DEBUG) {print STDERR "Doing node $node\n";} make_cfg($node); } print RRDINDEX "

Proxies Summary

\n"; close(RRDINDEX); rename("$rrdindexfilename.$$",$rrdindexfilename); untie (%XY); unlink($xyfile); rename("$xyfile.$$",$xyfile); open (FILE,">${revision_file}"); print FILE "$revision\n"; close(FILE); sub make_cfg { local($node)=@_; local($r,$if,$main,$wireless)=''; local($X,$Y,$Real_X,$RealY); local(%config,%DESC,%SDESC,%ANTENNA,%BEAMWIDTH,%CABLE,%CHANNEL,%DHCP,%DHCP_STATIC); local(%DIRECTION,%ESSID,%GAIN,%IP,%MODE,%NAT,%OSPF_AREA,%OSPF_BROADCAST); local(%OSPF_NEIGHBORS,%POINT_TO_POINT,%POLAR,%ROUTE,%SENS,%SPEED,%TXPOWER,%TYPE,%DISPLAY_LINK); local($labelpos,$neighbors,$link_file,$int_file); local(%ptp_done); chdir("/home/wleiden/genesis/nodes"); # $doit="curl -m 10 -sf http://www.wleiden.net/cgi-bin/g_list.pl/$node/config -o ${node}.pl"; # if ($DEBUG) {print STDERR "Fetching config for $node: $doit\n";} # system($doit); do "${node}/wleiden.conf" || return; parse_config(); $XY{"$node-XY"}="$X:$Y"; if ($Real_X) {$XY{"$node-RXY"}="$Real_X:$Real_Y";} $XY{"$node-labelpos"}=$labelpos; if ($nodetype=~/CNode|proxy/i) { local($rrd_traffic,$rrd_routes,$rrd_quality,$rrd_channels,$rrd_links)=(); local($rrd_traffic1,$rrd_traffic2,$rrd_traffic3,$rrd_traffic4,$rrd_traffic5)=(); local($rrd_routes1,$rrd_routes2)=(); local($rrd_quality1,$rrd_quality2)=(); local($rrd_channels1,$rrd_channels2)=(); local($linkc_counter)=10; local($ifc_counter)=0; $rrd_traffic=RRD_init("Traffic",'traffic','Bytes/s',250,'',"-${heartbeat}s"); $rrd_trafficSi="\tCDEF:TOTALi=0,"; $rrd_trafficSo="\tCDEF:TOTALo=0,"; $rrd_routes=RRD_init("Routes",'routes','Routes',100,'',"-${heartbeat}s"); $rrd_routes.=" --lower-limit 0 --rigid\n"; $rrd_routesS="\tCDEF:TOTAL=0,"; $rrd_quality=RRD_init("Quality",'quality','dB',100,'',"-${heartbeat}s"); $rrd_channels=RRD_init("Channels",'channels','',100,'',"-${heartbeat}s"); $rrd_channels.=" --lower-limit 1 --upper-limit 13 --rigid\n"; $dir="/home/wleiden/public_html/mrtg/$node"; if (! -d $dir) {mkdir($dir,0755) || die "$! $dir\n";} $rrddir="/home/wleiden/stats/rrd/data/$node"; if (! -d $rrddir) {mkdir($rrddir,0755) || die "$! $rrddir\n";} $rrdimgdir="/home/wleiden/stats/rrd/img/$node"; if (! -d $rrdimgdir) {mkdir($rrdimgdir,0777) || die "$! $rrdimgdir\n";} check_rrd_system_file("$rrddir/system.rrd",$heartbeat); check_rrd_icmp_file("$rrddir/icmp.rrd",$heartbeat); print RRDINDEX "$node
\n"; $rrdcgidir="/home/wleiden/stats/rrd/cgi/$node"; if (! -d $rrdcgidir) {mkdir($rrdcgidir,0755) || die "$! $rrdcgidir\n";;} $rrd_cgi_file="$rrdcgidir/interfaces.cgi"; open(CGI,">$rrd_cgi_file.$$") || die "$! $rrd_cgi_file\n"; print CGI init_cgi(); $filename="/home/wleiden/stats/mrtg/cfg/${node}.cfg"; open (MRTG,">$filename") || die die "$! $filename\n";; print MRTG <Http speed for $node Options[httpspeed]: transparent, gauge, nopercent WithPeak[httpspeed]: wmy Legendi[httpspeed]: tango Legendo[httpspeed]: proxy Target[total_bytes]: `$wlan_stats $node bytes-total` MaxBytes[total_bytes]: 10000000000 Title[total_bytes]: Total Traffic PageTop[total_bytes]:

Total Traffic on all interfaces

Options[total_bytes]: transparent, gauge, nopercent WithPeak[total_bytes]: wmy Target[total_users]: `$wlan_stats $node bytes-users` MaxBytes[total_users]: 10000000000 Title[total_users]: Total Users Traffic PageTop[total_users]:

Total Traffic on all Usersinterfaces

Options[total_users]: transparent, gauge, nopercent WithPeak[total_users]: wmy Target[total_links]: `$wlan_stats $node bytes-links` MaxBytes[total_links]: 10000000000 Title[total_links]: Total Link Traffic PageTop[total_links]:

Total Traffic on all Link interfaces

Options[total_links]: transparent, gauge, nopercent WithPeak[total_links]: wmy Target[total_ospf]: `$wlan_stats $node bytes-ospf` MaxBytes[total_ospf]: 10000000000 Title[total_ospf]: Total OSPF Traffic PageTop[total_ospf]:

Total OSPF Traffic on all Link interfaces

Options[total_ospf]: transparent, gauge, nopercent WithPeak[total_ospf]: wmy Target[${node}_uptime]: `$wlan_stats $node fetch` MaxBytes[${node}_uptime]: 1000 Title[${node}_uptime]: $node Uptime PageTop[${node}_uptime]:

$node Uptime

Options[${node}_uptime]: transparent, gauge, nopercent Legendi[${node}_uptime]: uptime Legendo[${node}_uptime]: ShortLegend[${node}_uptime]: Days YLegend[${node}_uptime]: Days WithPeak[${node}_uptime]: wmy Target[${node}_load]: `$wlan_stats $node cpuload` MaxBytes[${node}_load]: 1000 Title[${node}_load]: CPU load on $node PageTop[${node}_load]:

CPU load on $node

Options[${node}_load]: transparent, gauge, nopercent Legendi[${node}_load]: 5min Legendo[${node}_load]: 15min ShortLegend[${node}_load]: % YLegend[${node}_load]: % WithPeak[${node}_load]: wmy Target[${node}_mem]: `$wlan_stats $node mem` MaxBytes[${node}_mem]:300000000 Title[${node}_mem]: Memory usage on $node PageTop[${node}_mem]:

Memory usage on $node

Options[${node}_mem]: transparent, gauge, nopercent Legendi[${node}_mem]: free Legendo[${node}_mem]: swap ShortLegend[${node}_mem]: Bytes YLegend[${node}_mem]: Bytes WithPeak[${node}_mem]: wmy Target[${node}_routes]: `$wlan_stats $node routes` MaxBytes[${node}_routes]: 3000 Title[${node}_routes]: Routes on $node PageTop[${node}_routes]:

Routes on $node

Options[${node}_routes]: transparent, gauge, nopercent Legendi[${node}_routes]: routes Legendo[${node}_routes]: ShortLegend[${node}_routes]: routes YLegend[${node}_routes]: routes WithPeak[${node}_routes]: wmy ############################################################### EOR1 foreach $if (sort keys %config) { if ($if!~/:\d+/) {$main=1;} else {$main=0;} if ($if=~/^([^:]+):(\d+)/) {$mymain=$1;$mysub=$2;} else {$mymain=$if;} $ip=$IP{$if}; $ip=~s/\/(\d+)$//;$XY{$ip}=$node; $IF=$if;$IF=~s/[^a-z0-9_-]/_/gi; if (! $main) { $speed=$SPEED{$mymain}; if ($speed!~/\d+/) {$speed= 10000000000;} print MRTG <Traffic on ${if} $DESC{$if} Options[${IF}_bytes]: transparent WithPeak[${IF}_bytes]: wmy EOM21s } else # main: { $speed=$SPEED{$if}; if ($speed!~/\d+/) {$speed=10000000000;} check_rrd_interface($rrddir,$if,$heartbeat); $int_file="$rrddata//int-${if}.rrd"; $rrd_traffic1.="\tDEF:${if}_b_in=$int_file:bytes_in:AVERAGE\n"; $rrd_traffic2.="\tDEF:${if}_b_out=$int_file:bytes_out:AVERAGE\n"; $rrd_trafficSi.="U${if}_b_in,+,"; $rrd_trafficSo.="UN${if}_b_out,+,"; if ($rrd_traffic4) {$STACK='STACK';} else {$STACK='AREA';$rrd_traffic3="\tCDEF:Null=${if}_b_out,UN,0,*\n";} $rrd_traffic3.="\tCDEF:N${if}_b_out=0,${if}_b_out,-\n"; $ifcolor='#' . $COLORS[$ifc_counter+=3]; $rrd_traffic4.=addData("${if}_b_in",$ifcolor,"${if} in",$STACK,"%sB/s"); #"\t$STACK:${if}_bytes_in${ifcolor}:\"${if}\"\n"; $rrd_traffic5.=addData("N${if}_b_out",$ifcolor,"${if} out",$STACK,"%sB/s"); #"\t$STACK:N${if}_bytes_out${ifcolor}:\n"; $rrd_routes1.="\tDEF:${if}_routes=$int_file:routes:AVERAGE\n"; $rrd_routesS.="U${if}_routes,+,"; if ($rrd_routes2) {$STACK='STACK';} else {$STACK='AREA';} $rrd_routes2.=addData("${if}_routes",$ifcolor,"${if}",$STACK,""); #"\t$STACK:${if}_routes${ifcolor}:\"${if}\"\n"; if ($TYPE{$if}=~/wireless/i) { $rrd_channels1.="\tDEF:${if}_channel=$int_file:channel:AVERAGE\n"; $rrd_channels2.=addData("${if}_channel",$ifcolor,"${if}","LINE2",""); #"\tLINE2:${if}_channel${ifcolor}:\"${if}\"\n"; } print MRTG <Total Traffic on ${if} Options[${IF}_bytes]: transparent WithPeak[${IF}_bytes]: wmy EOM21 if ($IP{"${if}:0"}) { print MRTG <Traffic on ${if}_ $DESC{$if} Options[${IF}__bytes]: transparent WithPeak[${IF}__bytes]: wmy Target[${IF}_routes]: `$wlan_stats $node routes-${if}` MaxBytes[${IF}_routes]: 10000 Title[${IF}_routes]: routes on ${if} PageTop[${IF}_routes]:

routes on ${if}

Options[${IF}_routes]: transparent, gauge, nopercent Legendi[${IF}_routes]: routes: Legendo[${IF}_routes]: WithPeak[${IF}_routes]: wmy EOM22 } if ($TYPE{$if}=~/wireless/) { if (($DIRECTION{$if} > 0) && ($BEAMWIDTH{$if} ne 360)) { $XY{"DIR_${node}_$ESSID{$if}"}=$DIRECTION{$if}; } if ($MODE{$if}=~/master/) { $XY{"${node}-M"}.=":$ESSID{$if}=$POINT_TO_POINT{$if}=$if:"; $XY{"$ESSID{$if}-E"}=$node; print MRTG<Users on ${if} Options[${IF}_users]: transparent, gauge, nopercent Legendi[${IF}_users]: users Legendo[${IF}_users]: ShortLegend[${IF}_users]: users YLegend[${IF}_users]: users WithPeak[${IF}_users]: wmy EOM2 } else {$XY{"${node}-S"}.=":$ESSID{$if}=$POINT_TO_POINT{$if}=$if:";} print MRTG <Beacons on ${if} Options[${IF}_beacons]: transparent, gauge, nopercent Legendi[${IF}_beacons]: beacons Legendo[${IF}_beacons]: ShortLegend[${IF}_beacons]: beacons YLegend[${IF}_beacons]: beacons WithPeak[${IF}_beacons]: wmy Target[${IF}_TXspeed]: `$wlan_stats $node TX-speed-${if}` MaxBytes[${IF}_TXspeed]: 100000000 Title[${IF}_TXspeed]: TX Speed on ${if} PageTop[${IF}_TXspeed]:

TX Speed on ${if}

Options[${IF}_TXspeed]: transparent, gauge, nopercent, bits Legendi[${IF}_TXspeed]: actual: Legendo[${IF}_TXspeed]: select: WithPeak[${IF}_TXspeed]: wmy EOM3 } # wireless else { if ($ETHER_ESSID{$if}) #Artifical display ethernet bridge link. { $XY{"${node}-S"}.=":$ETHER_ESSID{$if}=$POINT_TO_POINT{$if}=$if:"; } } } # main check_rrd_links($rrddir,$if,$heartbeat); $nname=lc($SDESC{$if}); $desc=$DESC{$if}; # if ($a++ >1) {$nname.=$a;} if ($OSPF_NEIGHBORS{$if}!~/no|off/i) { $neighbors="$OSPF_NEIGHBORS{$if} ";$a=0; foreach $neighbor (split(/\s+/,$neighbors)) { print MRTG<routes on ${if} via $neighbor Options[routes-$mymain-$neighbor]: transparent, gauge, nopercent Legendi[routes-$mymain-$neighbor]: routes: Legendo[routes-$mymain-$neighbor]: WithPeak[routes-$mymain-$neighbor]: wmy EOM31 if ($TYPE{$if}=~/wireless/) { print MRTG<Signal and Noise for $desc on ${if} Options[snr-${mymain}-$nname]: transparent, gauge, nopercent Legendi[snr-${mymain}-$nname]: Signal: Legendo[snr-${mymain}-$nname]: Noise: ShortLegend[snr-${mymain}-$nname]: dBm YLegend[snr-${mymain}-$nname]: dBm WithPeak[snr-${mymain}-$nname]: wmy Target[qual-${mymain}-$nname]: `$wlan_stats $node qual-${mymain}-$neighbor` MaxBytes1[qual-${mymain}-$nname]: 100 MaxBytes2[qual-${mymain}-$nname]: 100 Title[qual-${mymain}-$nname]: Quality $desc on ${if} PageTop[qual-${mymain}-$nname]:

Quality for $desc on ${if}

Options[qual-${mymain}-$nname]: transparent, gauge, nopercent Legendi[qual-${mymain}-$nname]: Quality: Legendo[qual-${mymain}-$nname]: ShortLegend[qual-${mymain}-$nname]: dBm YLegend[qual-${mymain}-$nname]: dBm WithPeak[qual-${mymain}-$nname]: wmy Target[lat-$nname]: `$wlan_stats $node latency-$neighbor` MaxBytes1[lat-$nname]: 100 MaxBytes2[lat-$nname]: 600 Title[lat-$nname]: Latency/PktLoss Analysis $desc on ${if} PageTop[lat-$nname]:

Latency/PktLoss on $desc in ${if}

Options[lat-$nname]: transparent, gauge, nopercent Legendi[lat-$nname]: PacketLoss% Legendo[lat-$nname]: Avg. Latency (ms) ShortLegend[lat-$nname]: %/ms YLegend[lat-$nname]: %/ms WithPeak[lat-$nname]: wmy EOM4 } # Wireless } # neighbor } # OSPF foreach $ptp (split(/\s+/,$neighbors . " " . $POINTOPOINT{$if})) { if (exists($ptp_done{$ptp})) {next;} $ptp_done{$ptp}=1; $_ptp=$ptp;$_ptp=~s/\./_/gi; $lcolor='#' . $COLORS[$linkc_counter++]; local($iaddr) = inet_aton($ptp); # or whatever address local($hostname) = gethostbyaddr($iaddr, AF_INET); $hostname=~s/^[^.]+\.([^.]+)\..*$/$1/i; $hostname=~s/.node//i; # print "HM:$ptp=$hostname\n"; $rrd_links.="

Link to $ptp on $if

\n"; local($a,$s); $a=addData("${_ptp}_AvgNoise","#00FF00","Noise","AREA","dB"); $s=addData("${_ptp}_AvgSignal","#0000FF","Signal","LINE2","dB"); # AREA:${_ptp}_AvgNoise#00FF00:"Noise" # LINE2:${_ptp}_AvgSignal#0000FF:"Signal" if ($TYPE{$mymain}=~/wireless/i) { $rrd_links.=RRD_init("Signal/Noise to 2$hostname on $if","snr-$ptp",'dB',100,'',"-${heartbeat}s"); $link_file="$rrddata//link-${ptp}.rrd"; $rrd_links.=<

\n EOR $a=addData("InBytes","#00FF00","In","AREA","%sB/s"); $s=addData("NOutBytes","#0000FF","Out","AREA","%sB/s"); # AREA:InBytes#00FF00: # AREA:NOutBytes#00FF00: $rrd_links.=RRD_init("Traffic 2$hostname on $if","traffic-$ptp",'Bytes/s',100,'',"-${heartbeat}s"); $rrd_links.=<

\n EOR # AREA:AvgInBandwidth#00FF00:"Avg" # LINE2:DevInBandwidth#0000FF:"Dev" # AREA:NAvgOutBandwidth#00FF00: # LINE2:NDevOutBandwidth#0000FF: $a=addData("AvgInBandwidth","#00FF00","AvgIn","AREA","%sB/s"); $a.=addData("DevInBandwidth","#0000FF","DevIn","LINE2","%sB/s"); $s=addData("NAvgOutBandwidth","#00FF00","AvgOut","AREA","%sB/s"); $s.=addData("NDevOutBandwidth","#0000FF","DevOut","LINE2","%sB/s"); $rrd_links.=RRD_init("Bandwith 2$hostname on $$if","bandw-$ptp",'Bytes/s',100,'',"-${heartbeat}s"); $rrd_links.=<

\n EOR $rrd_quality1.="\tDEF:${_ptp}_AvgQuality=$link_file:AvgQuality:AVERAGE\n"; $rrd_quality2.=addData("${_ptp}_AvgQuality",$lcolor,"2$hostname","LINE2","dB"); #"\tLINE2:${_ptp}_AvgQuality${lcolor}:\"2$hostname\"\n"; #print "PTP=$ptp [$neighbors|$POINTOPOINT{$if}|$if|\n"; } # type=Wireless } # foreach ptp } # foreach $if print MRTG "################# Latency key nodes #############\n"; foreach $ip (sort keys %PINGNODE) { $pingnode=$PINGNODE{$ip}; print MRTG<Latency/PktLoss to $pingnode Options[lat-$pingnode]: transparent, gauge, nopercent Legendi[lat-$pingnode]: PacketLoss% Legendo[lat-$pingnode]: Avg. Latency (ms) ShortLegend[lat-$pingnode]: %/ms YLegend[lat-$pingnode]: %/ms WithPeak[lat-$pingnode]: wmy EOMP } close(MRTG); $rrd_trafficSi=~s/,$//; $rrd_trafficSo=~s/,$//; $color="#000000"; $rrd_traffic.=$rrd_traffic1 ."\n". $rrd_traffic2 ."\n". $rrd_traffic3 ."\n". $rrd_traffic4 ."\n". $rrd_traffic5 ."\n". "\tLINE2:Null#000000:" . "$rrd_trafficSi\n$rrd_trafficSo\n" . addData("TOTALi",$color,"totaal in",'LINE1',"%sB/s") . addData("TOTALo",$color,"totaal out",'LINE1',"%sB/s") . "\n>\n\n"; $rrd_routes.="${rrd_routes1}\n${rrd_routes2}\n${rrd_routesS}\n" . addData("TOTAL",$color,"totaal",'LINE1') . ">\n

\n\n"; $rrd_channels.=$rrd_channels1 ."\n". $rrd_channels2 .">

\n\n"; $rrd_quality.=$rrd_quality1 ."\n". $rrd_quality2 .">

\n\n"; if ($node=~/proxy/){$proxy="

Proxy stats

\n";} else {$proxy='';} print CGI < EOC close(CGI); chmod(0755,"$rrd_cgi_file.$$"); unlink($rrd_cgi_file); rename("$rrd_cgi_file.$$",$rrd_cgi_file); system("indexmaker $filename > $dir/index.html"); } elsif ($nodetype=~/HNode/i) { $XY{$ip}=$node; if ($MODE=~/managed/i) {$XY{"${node}-S"}.=":$ESSID==:";} else {$XY{"${node}-M"}.=":$ESSID=$ip=wi0:";$XY{"${ESSID}-E"}=$node;} } } #make_cfg sub parse_config { foreach $if (keys %config) { $cfg=$config{$if}; #if (! $html) {print "Parsing interface: $if\n";} while ($cfg) { $cfg=~s/^([^\n\r]+)[\r\n]*//m; $line=$1; $line=~s/\s*#.*//; if ((($name,$value)=split(/=/,$line)) eq 2) { #print "VAL($name)=$value\n"; $doit="if (exists(\$$name\{\"$if\"\})) {\$$name\{\"$if\"\}.=\"$separator$value\";} else {\$$name\{\"$if\"\}.=\"$value\";}"; #print "DOIT: [$doit]\n"; eval($doit); } #print "CFG:[$cfg]\n"; $cfg=~s/[\r\n]*$//m; } } #if ($functions_only<1) {print "Done parsing config.\n";} } sub check_rrd_system_file { local($file,$timeout)=@_; if ( -e $file) {return();} $DS=< <RRD::CV RRD_NODE> Interface statistieken <RRD::CV RRD_START>

Interface statistieken

Start graph at:

-1, -4, -8. -24 hours. -4 days. -7 days. -1 month. -6 months. -1 year. >
EOS } sub RRD_init { local($Desc,$sdesc,$Yunit,$height,$log,$end)=@_; if ($sdesc eq '') {$sdesc=lc($Desc);$sdesc=~s/\s+/_/gi;$sdesc=~s/[^a-z0-9]//gi;} if ($Yunit eq '') {$Yunit='Bytes/s';} if ($height) {$heigth="--height $height";} if ($log) {$log="-logarithmic";} if ($end eq '') {$end="now";} return <.png -a PNG -v '$Yunit' $heigth $log --alt-autoscale-max --imginfo '' --lazy --start --end $end --title="$Desc $node" $comment EOS } 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)=<