#!/usr/bin/perl # This script graphs 4 variable: # LAN eth in and out and; # LAN WiFi in and out use strict; use RRDs; # define location of rrdtool databases my $rrd_dir = '/var/lib/rrd'; # define name of database my $rrd = 'airport_lan'; # define location of images my $img_dir = '/var/www/www.bacik.org/htdocs/rrdtool'; # define host for SNMP my $snmp_host = 'airport.bacik.org'; # get network interfact info my $in_eth = `/usr/bin/snmpget -v 1 -c public -Oqv $snmp_host IF-MIB::ifInOctets.1`; my $out_eth = `/usr/bin/snmpget -v 1 -c public -Oqv $snmp_host IF-MIB::ifOutOctets.1`; my $in_wifi = `/usr/bin/snmpget -v 1 -c public -Oqv $snmp_host IF-MIB::ifInOctets.2`; my $out_wifi = `/usr/bin/snmpget -v 1 -c public -Oqv $snmp_host IF-MIB::ifOutOctets.2`; # remove eol chars chomp($in_eth); chomp($out_eth); chomp($in_wifi); chomp($out_wifi); # if rrdtool database doesn't exist, create it if (! -e "$rrd_dir/$rrd.rrd") { print "Creating $rrd_dir/$rrd.rrd\n"; RRDs::create("$rrd_dir/$rrd.rrd", "-s 300", "DS:in_eth:DERIVE:600:0:12500000", "DS:out_eth:DERIVE:600:0:12500000", "DS:in_wifi:DERIVE:600:0:12500000", "DS:out_wifi:DERIVE:600:0:12500000", "RRA:AVERAGE:0.5:1:576", "RRA:AVERAGE:0.5:6:672", "RRA:AVERAGE:0.5:24:732", "RRA:AVERAGE:0.5:144:1460"); my $ERR=RRDs::error; die "ERROR while creating $rrd_dir/$rrd.rrd: $ERR\n" if $ERR; } # insert values into rrd RRDs::update("$rrd_dir/$rrd.rrd","-t", "in_eth:out_eth:in_wifi:out_wifi", "N:$in_eth:$out_eth:$in_wifi:$out_wifi"); my $ERR=RRDs::error; die "ERROR while updating $rrd.rrd: $ERR\n" if $ERR; &make_graph ("day"); &make_graph ("week"); &make_graph ("month"); &make_graph ("year"); exit (1); ##################################### sub make_graph { RRDs::graph ("$img_dir/$rrd-$_[0].png", "-s -1$_[0]", # Start "-w 600", # Width "-h 100", # Height # "-z", # Lazy "-aPNG", # Image format "-i", # Interlaced "-t Traffic on Airport LAN for past $_[0]", # Title "-v bytes/sec", # Verticle label "-E", # Slope mode "-u 1000", # Upper limit "-l 0", # Lower limit # COLOURS # "-cBACK#000000", # Outer background colour # "-cCANVAS#000000", # Graph background colour # "-cSHADEA#00FF00", # Top and left shade line colour # "-cSHADEB#0000FF", # Bottom and right shade line colour # "-cGRID#FFFFFF", # Grid colour # "-cMGRID#FFFFFF", # Grid colour "-cFONT#003399", # Font colour # "-cAXIS#000000", # Grid axis colours # "-cFRAME#00FF00", # Frame colour for legend descriptions # "-cARROW#00FF00", # Arrow colour # FONTS "-nDEFAULT:0:/usr/local/rrdtool-1.2.23/share/rrdtool/fonts/Verdana.ttf", # Set default font "-nTITLE:13:", # Title font size "-nAXIS:6:", # Axis font size "-nUNIT:8", # Unit font size "-nLEGEND:8", # Legend font size "-W airport.bacik.org", # Watermark "-X 3", # Unit exponent "DEF:in_eth=$rrd_dir/$rrd.rrd:in_eth:AVERAGE", "DEF:out_eth=$rrd_dir/$rrd.rrd:out_eth:AVERAGE", "DEF:in_wifi=$rrd_dir/$rrd.rrd:in_wifi:AVERAGE", "DEF:out_wifi=$rrd_dir/$rrd.rrd:out_wifi:AVERAGE", # in_eth "LINE2:in_eth#487AAF:Eth in ", # Line width 2 "GPRINT:in_eth:MAX: Max\\: %5.0lf %s", "GPRINT:in_eth:AVERAGE: Avg\\: %5.0lf %S", "GPRINT:in_eth:LAST: Current\\: %5.0lf %Sbytes/sec\\n", # out_eth "LINE2:out_eth#6DB5EF:Eth out ", "GPRINT:out_eth:MAX: Max\\: %5.0lf %S", "GPRINT:out_eth:AVERAGE: Avg\\: %5.0lf %S", "GPRINT:out_eth:LAST: Current\\: %5.0lf %Sbytes/sec\\n", # in_wifi "LINE2:in_wifi#1F591F:WiFi in ", # Line width 2 "GPRINT:in_wifi:MAX: Max\\: %5.0lf %s", "GPRINT:in_wifi:AVERAGE: Avg\\: %5.0lf %S", "GPRINT:in_wifi:LAST: Current\\: %5.0lf %Sbytes/sec\\n", # out_wifi "LINE2:out_wifi#43C043:WiFi out", "GPRINT:out_wifi:MAX: Max\\: %5.0lf %S", "GPRINT:out_wifi:AVERAGE: Avg\\: %5.0lf %S", "GPRINT:out_wifi:LAST: Current\\: %5.0lf %Sbytes/sec"); my $ERR=RRDs::error; die "ERROR while creating $_[0] graph: $ERR\n" if $ERR; }