rrdflushcached: Do not free 'opt_daemon' before checking the connection. -- Sebastian...
[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/.*\///g;
10 $name =~ s/\.pl.*//g;
11
12 RRDs::create ($rrd, "--start",$start-1, "--step",300,
13               "DS:a:GAUGE:600:U:U",
14               "RRA:AVERAGE:0.5:1:300",
15               "RRA:MIN:0.5:12:300",
16               "RRA:MAX:0.5:12:300",
17 );
18 my $ERROR = RRDs::error;
19 die "$0: unable to create `$rrd': $ERROR\n" if $ERROR;
20
21 # dropt some data into the rrd
22 my $t;
23 for ($t=$start; $t<$start+300*300; $t+=300){
24   RRDs::update $rrd, "$t:".(sin($t/3000)*50+50);
25   if ($ERROR = RRDs::error) {
26     die "$0: unable to update `$rrd': $ERROR\n";
27   }
28 }
29
30 RRDs::graph "$name.png",
31   "--title", uc($name)." Demo", 
32   "--start", "now",
33   "--end", "start+1d",
34   "--lower-limit=0",
35   "--interlace", 
36   "--imgformat","PNG",
37   "--width=450",
38   "DEF:a=$rrd:a:AVERAGE",
39   "DEF:b=$rrd:a:MIN",
40   "DEF:c=$rrd:a:MAX",
41   "AREA:a#00b6e4:real",
42   "LINE1:b#0022e9:min",
43   "LINE1:c#00ee22:max",
44 ;
45
46 if ($ERROR = RRDs::error) {
47   die "ERROR: $ERROR\n";
48 };
49
50
51 print "This script has created $name.png in the current directory\n";
52 print "This demonstrates the use of MIN and MAX archives\n";