#!/usr/bin/perl

use strict;
use warnings;
use Time::HiRes qw(gettimeofday);
use RRDs;

my $RRD   = 'graphv32.rrd';
my $PNG   = 'graphv.png';
my $START = time-40*3600;
my $STEP  = 300;

if (-f $RRD) {
    unlink $RRD;
}

RRDs::create(
    $RRD,
    '--start', $START, '-s', $STEP,
    'DS:ds:COUNTER:600:0:U',
    'RRA:AVERAGE:0.5:1:600',
    'RRA:AVERAGE:0.5:6:700',
    'RRA:AVERAGE:0.5:24:775',
    'RRA:AVERAGE:0.5:288:797',
    'RRA:MAX:0.5:1:600',
    'RRA:MAX:0.5:6:700',
    'RRA:MAX:0.5:24:775',
    'RRA:MAX:0.5:288:797',
);
    print RRDs::error if RRDs::error;

for my $i (1..500) {
    RRDs::update($RRD, sprintf '%d:%d', $START + $i * 300, $i * 1000 + rand(500)-250);
    print RRDs::error if RRDs::error;
}

for (1..3){
my $start = scalar gettimeofday;
RRDs::graph(
    $PNG,
    '-t', 'Demo',
    '-l', 0,
    '-a', 'PNG',
    "DEF:a=$RRD:ds:AVERAGE",
    'AREA:a#00cc00:Value',
    'VDEF:a_max=a,MAXIMUM',
    'LINE:a_max#ff0000:hello',
    'PRINT:a_max:%.1lf',
);
print RRDs::error if RRDs::error;
print scalar gettimeofday - $start,"\n";
}
