new command rrdtool xport integrated
[rrdtool.git] / examples / piped-demo.pl.in
1 #! @PERL@ 
2
3 #makes things work when run without install
4 use lib qw( ../bindings/perl-piped/blib/lib  ../lib/perl );
5
6 #makes programm work AFTER install 
7 use lib qw( @prefix@/lib/perl );
8
9 use RRDp;
10
11 # this simpulates a standard mrtg-2.x setup ... we can use this to
12 # compare performance ...
13
14 $main::DEBUG=0;
15 $STEP = 300;
16 $RUNS = 12*24*30*6;
17 $GRUNS = 20;
18 $RRD = "piped-demo.rrd";
19 $SVG = "piped-demo.svg";
20 $PNG = "piped-demo.png";
21
22 # some magic to find the correct rrdtol executable
23 if ( -x "@prefix@/bin/rrdtool") {
24    RRDp::start "@prefix@/bin/rrdtool";
25 } elsif ( -x "../bin/rrdtool") {
26    RRDp::start "../bin/rrdtool";
27 } else {
28    RRDp::start "../src/rrdtool";
29 }
30
31 print "* Creating RRD with properties equivalent to mrtg-2.x logfile\n\n";
32
33 $START = time()-$RUNS*$STEP;
34
35 RRDp::cmd "create $RRD -b $START -s $STEP 
36         DS:in:GAUGE:400:U:U
37         DS:out:GAUGE:400:U:U
38         RRA:AVERAGE:0.5:1:600
39         RRA:AVERAGE:0.5:6:600
40         RRA:MAX:0.5:6:600
41         RRA:AVERAGE:0.5:24:600
42         RRA:MAX:0.5:24:600
43         RRA:AVERAGE:0.5:144:600
44         RRA:MAX:0.5:144:600";
45
46 $answer = RRDp::read;
47 ($user,$sys,$real) =  ($RRDp::user,$RRDp::sys,$RRDp::real);
48     
49 print "* Filling RRD with $RUNS Values. One moment please ...\n";
50 print "  If you are running over NFS this will take *MUCH* longer\n\n"; 
51
52 for ($i=$START+1;
53      $i<$START+$STEP*$RUNS;
54      $i+=$STEP+int((rand()-0.5)*7)){
55
56   $line = "update $RRD $i:".int(rand(100000)).":".int(rand(100000));
57   RRDp::cmd $line;
58   $answer = RRDp::read;
59 }
60
61 ($user1,$sys1,$real1) =  ($RRDp::user,$RRDp::sys,$RRDp::real);
62
63 printf "-- performance analysis Update test\n".
64        "   usr/upd: %1.5fs sys/upd: %1.5fs real/upd: %1.5fs upd/sec: %1.0f\n",
65   ($user1-$user)/($RUNS), ($sys1-$sys)/($RUNS), 
66   ($real1-$real)/($RUNS), ($RUNS)/($real1-$real);
67 print "\n";
68 # creating some graphs
69
70 print "* Creating $GRUNS SVG graphs: $SVG\n\n";
71 $now = time;
72 for ($i=0;$i<$GRUNS;$i++) {
73 RRDp::cmd "graph $SVG ", "--title 'Test GRAPH' ",
74         "--imgformat SVG --height 150 --vertical-label 'Dummy Units' ".
75         "--start now".(-$RUNS*$STEP),
76         "--color ARROW#bfbfbf",
77         "DEF:alpha=$RRD:in:AVERAGE",
78         "DEF:beta=$RRD:out:AVERAGE",
79         "CDEF:calc=alpha,beta,+,1.5,/",
80         "AREA:alpha#0022e9:Alpha",
81         "STACK:beta#00b871:Beta",
82         "STACK:calc#ff0091:Calc\\j",
83         "PRINT:alpha:AVERAGE:'Average Alpha\\: %1.2lf %S'",
84         "PRINT:alpha:MIN:'Min Alpha\\: %1.2lf %S'",
85         "PRINT:alpha:MAX:'Max Alpha\\: %1.2lf %S'",
86         "GPRINT:calc:AVERAGE:'Average calc\\: %1.2lf %S\\r'",
87         "GPRINT:calc:MIN:'Min calc\\: %1.2lf %S'",
88         "GPRINT:calc:MAX:'Max calc\\: %1.2lf %S'",
89         "VRULE:".($now-3600)."#008877:'60 Minutes ago'",
90         "COMMENT:'\\s'",
91         "COMMENT:'Graph created on: ".localtime(time())."\\c'";
92
93 $answer = RRDp::read;
94 }
95 ($user2,$sys2,$real2) =  ($RRDp::user,$RRDp::sys,$RRDp::real);
96
97 print "ANSWER:\n$$answer";
98
99 printf "\n-- average Time for one Graph\n".
100        "   usr/grf: %1.5fs sys/grf: %1.5fs real/grf: %1.5fs   graphs/sec: %1.2f\n",
101   ($user2-$user1)/$GRUNS, 
102   ($sys2-$sys1)/$GRUNS, 
103   ($real2-$real1)/$GRUNS, 
104   $GRUNS/($real2-$real1);
105
106 print "\n\n* Creating $GRUNS PNG graphs: $PNG\n\n";
107
108 $now = time;
109 ($user1,$sys1,$real1) =  ($RRDp::user,$RRDp::sys,$RRDp::real);
110 for ($i=0;$i<$GRUNS;$i++) {
111 RRDp::cmd "graph $PNG ", "--title 'Test GRAPH' ",
112         "--imgformat PNG --height 150 --vertical-label 'Dummy Units' ".
113         "--start now".(-$RUNS*$STEP),
114         "--color ARROW#bfbfbf",
115         "DEF:alpha=$RRD:in:AVERAGE",
116         "DEF:beta=$RRD:out:AVERAGE",
117         "CDEF:calc=alpha,beta,+,1.5,/",
118         "AREA:alpha#0022e9:Alpha",
119         "STACK:beta#00b871:Beta",
120         "STACK:calc#ff0091:Calc\\j",
121         "PRINT:alpha:AVERAGE:'Average Alpha\\: %1.2lf %S'",
122         "PRINT:alpha:MIN:'Min Alpha\\: %1.2lf %S'",
123         "PRINT:alpha:MAX:'Max Alpha\\: %1.2lf %S'",
124         "GPRINT:calc:AVERAGE:'Average calc\\: %1.2lf %S\\r'",
125         "GPRINT:calc:MIN:'Min calc\\: %1.2lf %S'",
126         "GPRINT:calc:MAX:'Max calc\\: %1.2lf %S'",
127         "VRULE:".($now-3600)."#008877:'60 Minutes ago'",
128         "COMMENT:'\\s'",
129         "COMMENT:'Graph created on: ".localtime(time())."\\c'";
130
131 $answer = RRDp::read;
132 }
133 ($user2,$sys2,$real2) =  ($RRDp::user,$RRDp::sys,$RRDp::real);
134
135 print "ANSWER:\n$$answer";
136
137 printf "\n-- average Time for one PNG Graph\n".
138        "   usr/grf: %1.5fs sys/grf: %1.5fs real/grf: %1.5fs".
139        "  graphs/sec: %1.2f\n\n",
140   ($user2-$user1)/$GRUNS, 
141   ($sys2-$sys1)/$GRUNS, 
142   ($real2-$real1)/$GRUNS, 
143   $GRUNS/($real2-$real1);
144
145 RRDp::end;