revamped configure system ... lots more stuff is in acinclude now still a
[rrdtool.git] / examples / 4charts.pl.in
1 #! @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 # this is for after install
6 use lib qw( @prefix@/lib/perl ../lib/perl );
7
8 use RRDs;
9
10 my $start=time;
11 my $rrd="randome.rrd";
12 my $name = $0;
13 $name =~ s/\.pl.*//g;
14
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:300",
19               "RRA:MIN:0.5:12:300",
20               "RRA:MAX:0.5:12:300",
21 );
22
23 my $ERROR = RRDs::error;
24 die "$0: unable to create `$rrd': $ERROR\n" if $ERROR;
25
26 # dropt some data into the rrd
27 my $t;
28 for ($t=$start; $t<$start+300*300; $t+=300){
29   RRDs::update $rrd, "$t:".(sin($t/3000)*50+50).":".(sin($t/2500)*50+50);
30   if ($ERROR = RRDs::error) {
31     die "$0: unable to update `$rrd': $ERROR\n";
32   }
33 }
34
35 my $c1="f57912a0";
36 my $c2="2a79e9a0";
37 my $w=300;
38 my $h=140;
39
40 RRDs::graph "$name-L.png",
41   "--title", "2 LINES", 
42   "--start", "now",
43   "--end", "start+15h",
44   "--lower-limit=0",
45   "--interlace", 
46   "--imgformat","PNG",
47   "--width=$w",
48   "--height=$h",
49   "DEF:a=$rrd:a:AVERAGE",
50   "DEF:b=$rrd:b:AVERAGE",
51   "LINE1:a#$c1:Value A",
52   "LINE3:b#$c2:Value B",
53 ;
54
55 RRDs::graph "$name-A.png",
56   "--title", "LINE and AREA", 
57   "--start", "now",
58   "--end", "start+15h",
59   "--lower-limit=0",
60   "--interlace", 
61   "--imgformat","PNG",
62   "--width=$w",
63   "--height=$h",
64   "DEF:a=$rrd:a:AVERAGE",
65   "DEF:b=$rrd:b:AVERAGE",
66   "AREA:a#$c1:Value A",
67   "LINE2:b#$c2:Value B",
68 ;
69
70 RRDs::graph "$name-S.png",
71   "--title", "STACKED AREAS", 
72   "--start", "now",
73   "--end", "start+15h",
74   "--lower-limit=0",
75   "--interlace", 
76   "--imgformat","PNG",
77   "--width=$w",
78   "--height=$h",
79   "DEF:a=$rrd:a:AVERAGE",
80   "DEF:b=$rrd:b:AVERAGE",
81   "AREA:a#$c1:Value A",
82   "STACK:b#$c2:Value B",
83 ;
84
85
86 RRDs::graph "$name-M.png",
87   "--title", "RPN Magic", 
88   "--start", "now",
89   "--end", "start+15h",
90   "--lower-limit=0",
91   "--interlace", 
92   "--imgformat","PNG",
93   "--width=$w",
94   "--height=$h",
95   "DEF:a=$rrd:a:AVERAGE",
96   "DEF:b=$rrd:b:AVERAGE",
97   "CDEF:alpha=TIME,3600,%,1800,LT,a,UNKN,IF",
98   "CDEF:beta=TIME,3600,%,1800,GE,b,UNKN,IF",
99   "AREA:alpha#$c1:Value A",
100   "LINE1:a#$c1",
101   "AREA:beta#$c2:Value B",
102   "LINE1:b#$c2",
103 ;
104
105 RRDs::graph "$name-sample.png",
106   "--title", "Sample", 
107   "--start", "now",
108   "--end", "start+15h",
109   "--lower-limit=0",
110   "--interlace", 
111   "--imgformat","PNG",
112   "--width=600",
113   "--height=50",
114   "DEF:a=$rrd:a:AVERAGE",
115   "DEF:b=$rrd:a:MAX",
116   "AREA:a#00ff00:Incoming",
117   "LINE1:b#ff0000:Max Incoming",
118 ;
119
120 if ($ERROR = RRDs::error) {
121   print "ERROR: $ERROR\n";
122 };
123
124 print "This script has created $name.png in the current directory\n";
125 print "This demonstrates the use of the TIME and % RPN operators\n";