Sophie

Sophie

distrib > Mageia > 6 > x86_64 > media > core-release > by-pkgid > 85cc75d199bea60dc68be0e7a5028fbc > files > 10

perl-RRDTool-OO-0.360.0-3.mga6.noarch.rpm

#!/usr/local/bin/perl
############################################################
# Create a sample graph
# Mike Schilli <mschilli1@aol.com>, 2004
############################################################

use strict;
use warnings;

use RRDTool::OO;
use Log::Log4perl qw(:easy);
use DateTime;
Log::Log4perl->easy_init($DEBUG);

my $DB  = "example.rrd";
my $IMG = "example.png";

my $rrd = RRDTool::OO->new(file => $DB);

    # Use a reproducable point in time
my $start_time     = DateTime->now();
my $nof_iterations = 40;

   # Define the RRD
my $rc = $rrd->create(
    start       => $start_time->clone->subtract( hours => 1 ),
    step        => 60,
    data_source => { name      => 'load1',
                     type      => 'GAUGE',
                   },
    data_source => { name      => 'load2',
                     type      => 'GAUGE',
                   },
    archive     => { rows     => 50,
                   },
);

my $time = $start_time->clone()->subtract( minutes => 1);

   # Pump in values
for(0..$nof_iterations) {
    $time->add( minutes => 1 );
    my $value = 2 + $_ * 0.1;

    $rrd->update(
        time   => $time, 
        values => { 
            load1 => $value,
            load2 => $value+1,
        }
    );
}

   # Draw a graph of two different data sources,
   # stacked on top of each other
$rrd->graph(
    image          => $IMG,
    vertical_label => 'A Nice Area Graph',
    start          => $start_time,
    end            => $start_time->clone->add( minutes => $nof_iterations ),
    width          => 700,
    height         => 300,
    color          => { back   => '#eeeeee',
                        arrow  => '#ff0000',
                        canvas => '#eebbbb',
                      },
        # First graph
    draw           => {
        name      => 'some_stupid_draw',
        type      => "area",
        color     => '0000ff',
        legend    => 'first legend',
        dsname    => 'load1',
    },
        # Second graph
    draw           => {
        type      => "stack",
        color     => '00ff00',
        dsname    => 'load2',
        legend    => 'second legend',
    },
);

print "$IMG ready.\n";