LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-14-2004, 07:08 AM   #1
MaverickApollo
Member
 
Registered: Oct 2003
Distribution: Debian
Posts: 57

Rep: Reputation: 15
Anyone know anything about RRDTool?


I have the following Perl Script

Code:
#!/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 Drops");
&ProcessChain("DROP-FORWARD","Forward Chain Drops");

sub ProcessChain
{
# process interface
# inputs: $_[0]: Chain Name
#         $_[1]: Chain Description

        # get 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);

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

        # if rrdtool database doesn't exist, create it
        if (! -e "$rrd/$_[0].rrd")
        {
                print "creating rrd database for $_[0]...\n";
                RRDs::create "$rrd/$_[0].rrd",
                        "-s 300",
                        "DS:drop: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";
        }

        # 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",
                "-s -1$_[1]",
                "-t $_[0] :: $_[2]",
#               "--lazy",
                "-h", "80", "-w", "600",
                "-l 0",
                "-a", "PNG",
                "-v Packets",
                "DEF:drop=$rrd/$_[0].rrd:drop:AVERAGE",
                "CDEF:dropav=drop,3600,*",
                "AREA:dropav#32CD32:Dropped Packets",
                "LINE1:dropav#336600",
                "GPRINT:dropav:MAX:  Max\\: %5.0lf %s",
                "GPRINT:dropav:AVERAGE: Avg\\: %5.1lf %S",
                "GPRINT:dropav:LAST: Current\\: %5.0lf %SPackets",
                "HRULE:0#000000";
        if ($ERROR = RRDs::error) { print "$0: unable to generate $_[0] $_[1] traffic graph: $ERR$
}
Now this _does_ work, with one problem, the values are all wrong.

The graph looks like this

http://mains.bounceme.net/DROP-INPUT-day.png


As you can see, the current value is 12, however the command returns
4. So where is it getting the value of 12?

Could it be the fact that I am storing the Average value in the RRD? I have several other scripts that are virtually the same and they all return the correct values.

Can any one offer any help???[/url]
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on RRDTOOL and maybe perl needed! cash_05 Linux - Software 1 09-05-2005 03:27 AM
rrdtool tommytomato Linux - Networking 0 02-23-2005 06:43 AM
lm-sensors and rrdtool JurajPsycho Linux - Software 2 02-03-2005 10:13 AM
RRDTool tommytomato Linux - General 1 09-24-2004 06:51 AM
use of rrdtool herc Linux - Software 1 09-22-2003 08:11 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration