[rrd-users] Help a new and slightly lost user! :(

Michael Thompson mike at thompsonmike.co.uk
Sat Nov 13 10:50:11 MET 2004


I am trying to graph the packets that my firewall is blocking, so far I have 
the following script,

#!/usr/bin/perl

use RRDs;

# define location of rrdtool databases
my $rrd = '/var/lib/rrd';
# define location of images
my $img = '/var/www/localhost/htdocs/temp/';

&ProcessChain("DROP-INPUT", "Input Chain Droppage");

sub ProcessChain
{
# process interface
# inputs: $_[0]: chain name
#         $_[1]: chain description

        # get network interface info
        my $in = `/sbin/iptables -L $_[0] -v | grep LOG | awk '{print \$1}'`;
        #my $out =`/sbin/iptables -L $_[0] -v | grep LOG | awk '{print \$2}'`;

        # remove eol chars
        chomp($in);
        #chomp($out);

        print "$_[0] Packets Blocked: $in\n";

        # if rrdtool database doesn't exist, create it
        if (! -e "$rrd/$_[0].rrd")
        {
                print "creating rrd database for $_[0] chain...\n";

                RRDs::create "$rrd/$_[0].rrd",
                        "-s 300",
                        "DS:drop:GAUGE: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";


        }
        # insert values into rrd
        RRDs::update "$rrd/$_[0].rrd",
                "-t", "drop",
                "N:$in";

        # create traffic graphs
        &CreateGraph($_[0], "day", $_[1]);
        &CreateGraph($_[0], "week", $_[1]);
        &CreateGraph($_[0], "month", $_[1]);
        &CreateGraph($_[0], "year", $_[1]);
}

sub CreateGraph
{
# creates graph
# inputs: $_[0]: chain name
#         $_[1]: interval (ie, day, week, month, year)
#         $_[2]: chain description


        RRDs::graph "$img/$_[0]-$_[1].png",
#                "--lazy",
                "-s -1$_[1]",
                "-t $_[0] :: $_[2]",
                "-h", "80", "-w", "600",
                "-a", "PNG",
                "-v packets",
                "DEF:drop=$rrd/$_[0].rrd:drop:AVERAGE",
                "LINE2:drop#0000FF:$_[2] ($_[0])",
                "GPRINT:drop:MIN:  Min\\: %2.lf",
                "GPRINT:drop:MAX: Max\\: %2.lf",
                "GPRINT:drop:AVERAGE: Avg\\: %4.1lf",
                "GPRINT:drop:LAST: Current\\: %2.lf packets\\n";

        if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] $_[1] 
traffic graph: $ERROR\n"; }
}


Now, this does not work! Can some one please point out my error? Or suggest a 
better way of doing this?

Many Thanks for your time


Michael.......

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list