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