started updating for 1.2 release
[rrdtool.git] / examples / minmax.pl.in
1 #! @PERL@
2
3 use lib qw( @prefix@/lib/perl );
4
5 use RRDs;
6 my $start=time;
7 my $rrd="randome.rrd";
8 my $name = $0;
9 $name =~ s/\.pl.*//g;
10
11 RRDs::create ($rrd, "--start",$start-1, "--step",300,
12               "DS:a:GAUGE:600:U:U",
13               "RRA:AVERAGE:0.5:1:300",
14               "RRA:MIN:0.5:12:300",
15               "RRA:MAX:0.5:12:300",
16 );
17 my $ERROR = RRDs::error;
18 die "$0: unable to create `$rrd': $ERROR\n" if $ERROR;
19
20 # dropt some data into the rrd
21 my $t;
22 for ($t=$start; $t<$start+300*300; $t+=300){
23   RRDs::update $rrd, "$t:".(sin($t/3000)*50+50);
24   if ($ERROR = RRDs::error) {
25     die "$0: unable to update `$rrd': $ERROR\n";
26   }
27 }
28
29 RRDs::graph "$name.png",
30   "--title", uc($name)." Demo", 
31   "--start", "now",
32   "--end", "start+1d",
33   "--lower-limit=0",
34   "--interlace", 
35   "--imgformat","PNG",
36   "--width=450",
37   "DEF:a=$rrd:a:AVERAGE",
38   "DEF:b=$rrd:a:MIN",
39   "DEF:c=$rrd:a:MAX",
40   "AREA:a#00b6e4:real",
41   "LINE1:b#0022e9:min",
42   "LINE1:c#00ee22:max",
43 ;
44
45 if ($ERROR = RRDs::error) {
46   print "ERROR: $ERROR\n";
47 };
48
49
50 print "This script has created $name.png in the current directory\n";
51 print "This demonstrates the use of the TIME and % RPN operators\n";