5 print "not ok 1\n" unless $loaded;
11 my($what, $result) = @_ ;
13 print "not " unless $result;
14 print "ok $ok_count $what\n";
17 #makes things work when run without install
18 use lib qw( ../bindings/perl-shared/blib/lib ../bindings/perl-shared/blib/arch );
20 #makes programm work AFTER install
21 use lib qw( /usr/local/rrdtool-1.1.0/lib/perl ../lib/perl );
24 use vars qw(@ISA $loaded);
32 ######################### End of black magic.
37 my $RRD1 = "shared-demo.rrd";
38 my $RRD2 = "shared-demob.rrd";
39 my $GIF1 = "shared-demo1.gif";
40 my $GIF2 = "shared-demo2.gif";
41 my $time = 30*int(time/30);
42 my $START = $time-$RUNS*$STEP;
44 my @options = ("-b", $START, "-s", $STEP,
45 "DS:a:GAUGE:2000:U:U",
49 "DS:e:DERIVE:200:U:U",
50 "RRA:AVERAGE:0.5:1:5000",
51 "RRA:AVERAGE:0.5:10:500");
53 print "* Creating RRD $RRD1 starting at $time.\n\n";
54 RRDs::create $RRD1, @options;
56 my $ERROR = RRDs::error;
57 ok("create A", !$ERROR); # 2
59 die "$0: unable to create `$RRD1': $ERROR\n";
62 print "* Creating RRD $RRD2 starting at $time.\n\n";
63 RRDs::create $RRD2, @options;
66 ok("create B",!$ERROR); # 3
68 die "$0: unable to create `$RRD2': $ERROR\n";
71 my $last = RRDs::last $RRD1;
72 if ($ERROR = RRDs::error) {
73 die "$0: unable to get last `$RRD1': $ERROR\n";
75 ok("last A", $last == $START); # 4
77 $last = RRDs::last $RRD2;
78 if ($ERROR = RRDs::error) {
79 die "$0: unable to get last `$RRD2': $ERROR\n";
81 ok("last B", $last == $START); # 5
83 print "* Filling $RRD1 and $RRD2 with $RUNS*5 values. One moment please ...\n";
84 print "* If you are running over NFS this will take *MUCH* longer\n\n";
86 srand(int($time / 100));
92 $t<$START+$STEP*$RUNS;
93 $t+=$STEP+int((rand()-0.5)*7)){
94 $counter += 2500*sin($t/2000)*$STEP;
95 my $data = (1000+500*sin($t/1000)).":".
96 (1000+900*sin($t/2330)).":".
97 (2000*cos($t/1550)).":".
98 (3220*sin($t/3420)).":$counter";
99 push(@options, "$t:$data");
100 RRDs::update $RRD1, "$t:$data";
101 if ($ERROR = RRDs::error) {
102 die "$0: unable to update `$RRD1': $ERROR\n";
106 RRDs::update $RRD2, @options;
108 if ($ERROR = RRDs::error) {
109 die "$0: unable to update `$RRD2': $ERROR\n";
112 print "* Creating $GRUNS graphs: $GIF1 & $GIF2\n\n";
114 for (my $i=0;$i<$GRUNS;$i++) {
115 my @rrd_gifs = ($RRD1, $GIF1, $RRD2, $GIF2);
117 my $RRD = shift(@rrd_gifs);
118 my $GIF = shift(@rrd_gifs);
119 my ($graphret,$xs,$ys) = RRDs::graph $GIF, "--title", 'Test GRAPH',
121 "--vertical-label", 'Dummy Units', "--start", (-$RUNS*$STEP),
123 "--interlace", "--imgformat","GIF",
124 "DEF:alpha=$RRD:a:AVERAGE",
125 "DEF:beta=$RRD:b:AVERAGE",
126 "DEF:gamma=$RRD:c:AVERAGE",
127 "DEF:delta=$RRD:d:AVERAGE",
128 "DEF:epsilon=$RRD:e:AVERAGE",
129 "CDEF:calc=alpha,beta,+,2,/,100,*,102,/",
130 "AREA:alpha#0022e9:Short",
131 "GPRINT:calc:MAX:Max calc %1.2lf",
132 "STACK:beta#00b871:Demo Text",
133 "GPRINT:calc:AVERAGE:Average calc %1.2lf",
134 "STACK:beta#0ad871:Demo Text 2",
135 "LINE1:gamma#ff0000:Line 1",
136 "LINE2:delta#888800:Line 2",
137 "LINE3:calc#00ff44:Line 3",
138 "LINE3:epsilon#000000:Line 4",
139 "HRULE:1500#ff8800:Horizontal Line at 1500",
140 "PRINT:alpha:AVERAGE:Average Alpha %1.2lf",
141 "PRINT:alpha:MIN:Min Alpha %1.2lf",
142 "PRINT:alpha:MAX:Max Alpha %1.2lf",
143 "GPRINT:calc:MIN:Min calc %1.2lf",
144 "VRULE:".($now-3600)."#008877:60 Minutes ago",
145 "VRULE:".($now-7200)."#008877:120 Minutes ago";
147 if ($ERROR = RRDs::error) {
148 print "ERROR: $ERROR\n";
150 print "GIF Size: ${xs}x${ys}\n";
151 print "Graph Return:\n",(join "\n", @$graphret),"\n\n";
158 my ($start,$step,$names,$array) = RRDs::fetch $RRD1, "AVERAGE";
159 $ERROR = RRDs::error;
160 print "ERROR: $ERROR\n" if $ERROR ;
161 print "start=$start, step=$step\n";
163 map {printf("%12s",$_)} @$names ;
165 foreach my $line (@$array){
166 print "".localtime($start)," ";
168 foreach my $val (@$line) {
169 printf "%12.1f", $val;