The BIG graph update
[rrdtool.git] / examples / stripes.pl
1 #! /usr/bin/perl
2
3 #makes things work when run without install
4 use lib qw( ../bindings/perl-shared/blib/lib ../bindings/perl-shared/blib/arch );
5
6 #makes programm work AFTER install
7 use lib qw( /usr/local/rrdtool-1.1.0/lib/perl ../lib/perl );
8
9 use strict;
10 use vars qw(@ISA $loaded);
11
12 use RRDs;
13 my $start=time;
14 my $rrd="randome.rrd";
15 RRDs::create ($rrd, "--start",$start-1, "--step",300,
16               "DS:a:GAUGE:600:U:U",
17               "DS:b:GAUGE:600:U:U",
18               "RRA:AVERAGE:0.5:1:200");
19 my $ERROR = RRDs::error;
20 die "$0: unable to create `$rrd': $ERROR\n" if $ERROR;
21 my $t;
22 for ($t=$start; $t<$start+200*300; $t+=300){
23   RRDs::update $rrd, "$t:".rand(100).":".(sin($t/800)*50+50);
24   if ($ERROR = RRDs::error) {
25     die "$0: unable to update `$rrd': $ERROR\n";
26   }
27 }
28 RRDs::graph "stripes.png",
29   "--title", 'Stripes Demo', 
30   "--start", $start,
31   "--end", "start + 400 min",
32   "--interlace", 
33   "--imgformat","PNG",
34   "--width=450",
35   "DEF:a=$rrd:a:AVERAGE",
36   "DEF:b=$rrd:b:AVERAGE",
37   "CDEF:alpha=TIME,1200,%,600,LT,a,UNKN,IF",
38   "CDEF:beta=TIME,1200,%,600,GE,b,UNKN,IF",
39   "AREA:alpha#0022e9:alpha",
40   "AREA:beta#00b674:beta",
41   "LINE1:b#ff4400:beta envelope\\c",
42   "COMMENT:\\s",
43   "COMMENT:CDEF\:alpha=TIME,1200,%,600,LT,a,UNKN,IF",
44   "COMMENT:CDEF\:beta=TIME,1200,%,600,GE,b,UNKN,IF\\j";
45 if ($ERROR = RRDs::error) {
46   print "ERROR: $ERROR\n";
47 };
48
49
50 print "This script has created stripes.png in the current directory\n";
51 print "This demonstrates the use of the TIME and % RPN operators\n";