#!/usr/bin/perl
use lib "/home/tobi/rrdtool/lib/perl";
use RRDs;

# creation

RRDs::create ("demo.rrd",
	      "--start","now-80day", 
	      "--step",300,
              "DS:a:GAUGE:600:0:35000000",
              "DS:b:GAUGE:600:0:35000000",
              "RRA:AVERAGE:0.5:1:288",
              "RRA:AVERAGE:0.5:12:744",
              "RRA:MAX:0.5:12:744");

$ERR=RRDs::error;
die "ERROR while creating RRD: $ERR\n" if $ERR;

# updating

open X, "/home/tobi/rrdtool/data.txt" or die $!;
while (<X>) {
  chomp;
  RRDs::update "demo.rrd", $_;
  $ERR=RRDs::error;
  die "ERROR while creating RRD: $ERR\n" if $ERR;
}

# graphing 1;

RRDs::graph "lines.gif", "--end=19990930_15:00",
 "DEF:a=demo.rrd:a:AVERAGE",
  "LINE1:a#0000ff:value a",
 "DEF:b=demo.rrd:b:AVERAGE",
  "LINE1:b#00ff00:value b";
$ERR=RRDs::error;
die "ERROR while creating graph1: $ERR\n" if $ERR;

# GPRINT

RRDs::graph "gprint.gif", "--end=19990930_15:00",
 "DEF:a=demo.rrd:a:AVERAGE",
  "LINE1:a#0000ff:value a",
 "DEF:b=demo.rrd:b:AVERAGE",
  "LINE1:b#00ff00:value b",
 "DEF:ma=demo.rrd:a:MAX",
 "DEF:mb=demo.rrd:b:MAX",
 'GPRINT:ma:MAX:Max a %.2f %sbit/s',
 'GPRINT:mb:MAX:Max b %.2f %sbit/s\j';
  
$ERR=RRDs::error;
die "ERROR while updating graph: $ERR\n" if $ERR;

#graphing 2;

RRDs::graph "stack.gif","--end=19990930_15:00",
  "DEF:a=demo.rrd:a:AVERAGE",
  "AREA:a#0000ff:value a",
  "DEF:b=demo.rrd:b:AVERAGE",
  "STACK:b#00ff00:value b";
$ERR=RRDs::error;
die "ERROR while creating stack: $ERR\n" if $ERR;

#RPN ;

RRDs::graph "area8.gif","--end=19990930_15:00",
  "DEF:a=demo.rrd:a:AVERAGE",
  "CDEF:b=a,8,*",
  "AREA:b#0000ff:value a * 8",
$ERR=RRDs::error;
die "ERROR while creating area8: $ERR\n" if $ERR;



