Code

more examples
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 1 Oct 2008 17:15:59 +0000 (17:15 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Wed, 1 Oct 2008 17:15:59 +0000 (17:15 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@1553 a5681a0c-68f1-0310-ab6d-d61299d08faa

tutorial/lisa2008/rrd-by-example/ex/biggraph.pl [new file with mode: 0755]
tutorial/lisa2008/rrd-by-example/ex/graph-examples.pl
tutorial/lisa2008/rrd-by-example/ex/hw-demo.pl [new file with mode: 0755]
tutorial/lisa2008/rrd-by-example/ex/hw-example.pl [new file with mode: 0755]

diff --git a/tutorial/lisa2008/rrd-by-example/ex/biggraph.pl b/tutorial/lisa2008/rrd-by-example/ex/biggraph.pl
new file mode 100755 (executable)
index 0000000..f750083
--- /dev/null
@@ -0,0 +1,51 @@
+#!/usr/bin/perl
+#$ENV{PATH}='/scratch/rrd4/bin';
+use Math::BigInt;
+$ENV{PATH}=$ENV{HOME}.'/checkouts/rrdtool/branches/1.3/program/src:'.$ENV{PATH};
+my $R=rrdtool;
+my $w=320 ;
+my $h=200 ;
+my $start = 1199999700;
+if (not -f 'b.rrd'){
+    system $R,'create','b.rrd',
+          '--step' => 300,
+          '--start' => ($start-1),
+          'DS:a:COUNTER:600:U:U',
+          'RRA:AVERAGE:0.4:1:2100';
+
+    my @updates;
+    my $count = Math::BigInt->new(0);
+    my $add =  Math::BigInt->new('70000000000000') ;
+    for (my $i = 1; $i < 100;$i++){
+        $count = $count +  $add * Math::BigInt->new(''.int(rand(10)));
+        print "$count\n";
+        push @updates, ($i*300+$start).':'.$count;
+    }
+    system $R,'update','b.rrd',@updates;
+}
+
+sub rg {
+    my $file = shift;
+    print STDERR $file,"\t";
+    if (-f $file){
+        print STDERR " skip\n";
+        return;
+    }
+    my @G = ( '--start' => $start+3600,
+              '--end'   => $start + 100 * 280,
+#              '--full-size-mode',
+              '--color=BACK#ffff',
+              '--color=CANVAS#ffff',
+              '--color=SHADEA#ffff',
+              '--color=SHADEB#ffff',
+              '--lower-limit' => 0,
+              '--pango-markup',
+              '--height' => $h, '--width' => $w,
+              '--imgformat' => 'PDF',
+              'DEF:a=b.rrd:a:AVERAGE');
+   system $R, 'graph', $file, @G, @_;
+}
+
+rg 'bigLINE.pdf', 
+               '--lower-limit' => 1000,
+               'LINE:a#11a03b:DEF\:a=x.rrd\:a\:AVERAGE',
index 25acaf96d92aeb85abc589769a4047e92abe18ac..37bcb3d28627ef57af8d7303c541147992321f20 100755 (executable)
@@ -174,6 +174,7 @@ rg 'RPN-trend-start.pdf',
           'LINE1:r#3a1:a',   
           'LINE1:k#21f:b',                     
           'COMMENT:b=a,3600,TREND\l';
+
 rg 'RPN-trend-shift.pdf',         
           'DEF:rr=x.rrd:r:AVERAGE:start='.($start-3600),
           'CDEF:k=rr,3600,TREND',
@@ -182,6 +183,14 @@ rg 'RPN-trend-shift.pdf',
           'COMMENT:CDEF\:b=a,3600,TREND <b>SHIFT</b>\:b\:-1800',
           'LINE1:k#21f:b\l';                    
 
+if ( ! -f '1.rrd'){
+        system $R,'create','1.rrd',
+                  '--step' => 1,
+                  '--start' => ($start-1),
+                  'DS:a:GAUGE:2:U:U',
+                  'RRA:AVERAGE:0.4:1:1' };
+
+
 rg 'RPN-if.pdf',
           'CDEF:c=a,b,LT,a,b,IF,4,-',
           'LINE1:a#3a1:a',   
@@ -206,6 +215,23 @@ rg 'RPN-time-minus.pdf',
           'CDEF:c=TIME,1,-,1800,%,900,GE,a,UNKN,IF',
           'AREA:c#8a1:c=TIME,<b>1,-</b>,1800,%,900,GE,a,UNKN,IF';
 
+if ( ! -f '1.rrd'){
+        system $R,'create','1.rrd',
+                  '--step' => 1,
+                  '--start' => ($start-1),
+                  'DS:a:GAUGE:2:U:U',
+                  'RRA:AVERAGE:0.4:1:1' };
+
+rg 'RPN-time-odd.pdf',
+          'CDEF:c=TIME,1756,%,180,GE,a,UNKN,IF',
+          'AREA:c#8a1:c=TIME,1756,%,180,GE,a,UNKN,IF';
+
+rg 'RPN-time-odd-hires.pdf',
+          'DEF:s=1.rrd:a:AVERAGE',
+          'CDEF:c=s,POP,TIME,1756,%,180,GE,a,UNKN,IF',
+          'COMMENT:DEF\:one=1.rrd\:one\:AVERAGE',
+          'AREA:c#8a1:c=one,POP,TIME,1756,%,180,GE,a,UNKN,IF';
+
 rg 'RPN-prev.pdf',
           'CDEF:c=COUNT,3,%,0,EQ,a,UNKN,IF',
           'CDEF:d=COUNT,3,%,1,EQ,PREV,c,IF',
@@ -219,4 +245,27 @@ rg 'VDEF-average.pdf',
                'GPRINT:aavg:avg %.1lf',
                'COMMENT:<b>VDEF</b>\:b=a,AVERAGE <b>GPRINT</b>\:b\:avg %.1lf\l';
 
+rg 'VDEF-minmax.pdf', 
+               'LINE2:a#4f4',
+               'VDEF:amax=a,MAXIMUM',
+               'LINE:amax#123',
+               'VRULE:amax#123:max',          
+               'GPRINT:amax:%.1lf',
+               'GPRINT:amax:%H\:%M:strftime',
+               'COMMENT:VDEF\:max=a,MAXIMUM\l',
+               'VDEF:amin=a,MINIMUM',
+               'LINE:amin#48f',
+               'VRULE:amin#48f:min',
+               'GPRINT:amin:%.1lf',
+               'GPRINT:amin:%H\:%M:strftime',
+               'COMMENT:VDEF\:min=a,MINIMUM\l';
+
+rg 'VDEF-lsl.pdf', 
+               'VDEF:slope=a,LSLSLOPE',
+               'VDEF:int=a,LSLINT',                       
+               'CDEF:lsl=a,POP,COUNT,slope,*,int,+',
+               'GPRINT:slope:VDEF\:slope=a,LSLSLOPE (%.3lf)\l',
+               'GPRINT:int:VDEF\:int=a,LSLINT (%.1lf)\l',
+               'LINE2:a#8f1:a',
+               'LINE2:lsl#f71:lsl=a,POP,COUNT,slope,*,int,+\l';
 
diff --git a/tutorial/lisa2008/rrd-by-example/ex/hw-demo.pl b/tutorial/lisa2008/rrd-by-example/ex/hw-demo.pl
new file mode 100755 (executable)
index 0000000..baff57f
--- /dev/null
@@ -0,0 +1,111 @@
+#!/usr/bin/perl
+#$ENV{PATH}='/scratch/rrd4/bin';
+$ENV{PATH}=$ENV{HOME}.'/checkouts/rrdtool/branches/1.3/program/src:'.$ENV{PATH};
+my $R='rrdtool';
+my $width=600 ;
+my $height=200 ;
+
+$ENV{TZ}='MET';
+
+sub create {   
+    my %p = (@_);
+    my $start;
+    open my $fh,'<hw-demo.data';
+    my $end = (split /\s/, <$fh>)[0]; # drop the first line;
+    my @updates;
+    $start = $end;    
+    while (<$fh>){
+        my @line = split;
+        last if $start - $p{step} > $line[0];
+        $start = $line[0];
+        unshift @updates, join ":",@line[0,1,2];
+    }
+    system $R,'create','hw-demo.rrd',
+          '--step' => $p{step},
+          '--start' => ($start-1),
+          'DS:in:GAUGE:'.($p{step}*1.5).':U:U',
+          'DS:out:GAUGE:'.($p{step}*1.5).':U:U',
+          'RRA:AVERAGE:0.5:1:'.$p{rows},
+          'RRA:HWPREDICT:'.$p{rows}.':'.$p{alpha}.':'.$p{beta}.':'.$p{period};            
+    # it seems that resize is a bit broken ... will have to look into this
+    system $R,'resize','hw-demo.rrd',5,'GROW',$p{rows};
+    system $R,'dump','hw-demo.rrd','x';
+    system $R,'restore','x','x.rrd';
+    rename 'x.rrd','hw-demo.rrd';
+    unlink 'x';
+    system $R,'update','hw-demo.rrd',@updates;
+    return ($start,$end);
+}
+
+sub graph {
+    my $file = shift;
+    my $start = shift;
+    my $end = shift;
+    system $R, 'graph', $file,
+              '--lazy',
+              '--start' => $start,
+              '--end'   => $end,
+              '--color=BACK#ffff',
+              '--color=CANVAS#ffff',
+              '--color=SHADEA#ffff',
+              '--color=SHADEB#ffff',
+              '--lower-limit' => 0,
+              '--pango-markup',
+              '--height' => $height,
+              '--width' => $width,
+              '--imgformat' => 'PDF', @_;
+}
+
+sub quick {
+    my $period = shift;
+    my $alpha = shift;
+    my $beta = shift;
+    create ( step => 1800,
+             rows => 16*24*12,
+             period => $period,
+             alpha => $alpha,
+             beta => $beta );
+   my $file = "HW-p${period}-a${alpha}-b${beta}";
+   $file =~ s/\./_/g;
+   graph  $file.'.pdf', 
+          '00:00 20080916',
+          'start+8d',
+          'DEF:a=hw-demo.rrd:in:AVERAGE',
+          'DEF:pred=hw-demo.rrd:in:HWPREDICT',
+          'DEF:conf=hw-demo.rrd:in:DEVPREDICT',
+          'DEF:fail=hw-demo.rrd:in:FAILURES',
+          'TICK:fail#ff8:1:Failures',
+          'CDEF:lowc=pred,conf,2,*,-',
+          'CDEF:widc=conf,4,*',
+          'LINE1:lowc',
+          'AREA:widc#cfc:Band:STACK',
+          'LINE0.1:0#3a1::STACK',
+          'LINE0.1:lowc#3a1',             
+          'LINE1:a#c00:InOctets',
+          "LINE1:pred#0a0:Predicted p\\:$period, a\\:$alpha, b\\:$beta\\l";
+}
+    
+my ($start,$end) = create ( step => 1800,
+                            rows => 16*24*12,
+                            period => 24*2,
+                            alpha => 0.5,
+                            beta => 0.001 );
+
+$width=800;
+$height=100;
+graph  'HW-input.pdf', 
+       '00:00 20080916',
+       'start+14d',
+       'DEF:a=hw-demo.rrd:in:AVERAGE',
+       'LINE2:a#c00:InOctets';
+
+
+$width=450;
+$height=120;
+quick 1,0.5,0.001;
+quick 1,0.1,0.001;
+quick 1,0.1,0.1;
+quick 48,0.5,0.001;
+quick 48,0.2,0.001;
+quick 48,0.03,0.001;
+quick 48,0.03,0.1;
diff --git a/tutorial/lisa2008/rrd-by-example/ex/hw-example.pl b/tutorial/lisa2008/rrd-by-example/ex/hw-example.pl
new file mode 100755 (executable)
index 0000000..3748cc4
--- /dev/null
@@ -0,0 +1,57 @@
+#!/usr/bin/perl
+#$ENV{PATH}='/scratch/rrd4/bin';
+$ENV{PATH}=$ENV{HOME}.'/checkouts/rrdtool/branches/1.3/program/src:'.$ENV{PATH};
+my $R=rrdtool;
+my $w=1600 ;
+my $h=100 ;
+my $start = 1199999700;
+sub cr {
+    system $R,'create','h.rrd',
+          '--step' => 300,
+          '--start' => ($start-1),
+          'DS:a:GAUGE:600:U:U',
+          'RRA:AVERAGE:0.5:1:3100',
+          'RRA:HWPREDICT:3100:0.2:0.01:48';
+    my @updates;
+    for (my $i = 1; $i < 3000;$i++){
+        push @updates, ($i*300+$start).':'.(sin($i*3.14159265/24)*10*(cos($i/100)+3));
+
+    }
+    system $R,'update','h.rrd',@updates;
+}
+
+sub rg {
+    my $file = shift;
+    print STDERR $file,"\t";
+#    if (-f $file){
+#        print STDERR " skip\n";
+#        return;
+#    }
+    my @G = ( '--start' => $start-3600,
+              '--end'   => 'start+200h',
+#              '--full-size-mode',
+              '--color=BACK#ffff',
+              '--color=CANVAS#ffff',
+              '--color=SHADEA#ffff',
+              '--color=SHADEB#ffff',
+              '--lower-limit' => 0,
+              '--pango-markup',
+              '--height' => $h, '--width' => $w,
+              '--imgformat' => 'PDF');
+   system $R, 'graph', $file, @G, @_;
+}
+cr;
+
+rg 'HW-LINE.pdf', 
+               'DEF:a=h.rrd:a:AVERAGE',
+               'DEF:pred=h.rrd:a:HWPREDICT',
+               'DEF:conf=h.rrd:a:DEVPREDICT',
+               'CDEF:lowc=pred,conf,2,*,-',
+               'CDEF:widc=conf,4,*',
+               'LINE1:lowc',
+               'AREA:widc#cfc::STACK',
+               'LINE1:0#3a1::STACK',
+               'LINE1:lowc#3a1',             
+               'LINE1:a#a00:a\l';            
+#               'LINE1:pred#0a0:pred\l';
+