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