1 #!/usr/bin/perl
2 #$ENV{PATH}='/scratch/rrd4/bin';
3 $ENV{PATH}=$ENV{HOME}.'/checkouts/rrdtool/branches/1.3/program/src:'.$ENV{PATH};
4 my $R='rrdtool';
5 my $width=600 ;
6 my $height=200 ;
8 $ENV{TZ}='MET';
10 sub create {
11 my %p = (@_);
12 my $start;
13 open my $fh,'<hw-demo.data';
14 my $end = (split /\s/, <$fh>)[0]; # drop the first line;
15 my @updates;
16 $start = $end;
17 while (<$fh>){
18 my @line = split;
19 last if $start - $p{step} > $line[0];
20 $start = $line[0];
21 unshift @updates, join ":",@line[0,1,2];
22 }
23 system $R,'create','hw-demo.rrd',
24 '--step' => $p{step},
25 '--start' => ($start-1),
26 'DS:in:GAUGE:'.($p{step}*1.5).':U:U',
27 'DS:out:GAUGE:'.($p{step}*1.5).':U:U',
28 'RRA:AVERAGE:0.5:1:'.$p{rows},
29 'RRA:HWPREDICT:'.$p{rows}.':'.$p{alpha}.':'.$p{beta}.':'.$p{period};
30 # it seems that resize is a bit broken ... will have to look into this
31 system $R,'resize','hw-demo.rrd',5,'GROW',$p{rows};
32 system $R,'dump','hw-demo.rrd','x';
33 system $R,'restore','x','x.rrd';
34 rename 'x.rrd','hw-demo.rrd';
35 unlink 'x';
36 system $R,'update','hw-demo.rrd',@updates;
37 return ($start,$end);
38 }
40 sub graph {
41 my $file = shift;
42 my $start = shift;
43 my $end = shift;
44 system $R, 'graph', $file,
45 '--lazy',
46 '--start' => $start,
47 '--end' => $end,
48 '--color=BACK#ffff',
49 '--color=CANVAS#ffff',
50 '--color=SHADEA#ffff',
51 '--color=SHADEB#ffff',
52 '--lower-limit' => 0,
53 '--pango-markup',
54 '--height' => $height,
55 '--width' => $width,
56 '--imgformat' => 'PDF', @_;
57 }
59 sub quick {
60 my $period = shift;
61 my $alpha = shift;
62 my $beta = shift;
63 create ( step => 1800,
64 rows => 16*24*12,
65 period => $period,
66 alpha => $alpha,
67 beta => $beta );
68 my $file = "HW-p${period}-a${alpha}-b${beta}";
69 $file =~ s/\./_/g;
70 graph $file.'.pdf',
71 '00:00 20080916',
72 'start+8d',
73 'DEF:a=hw-demo.rrd:in:AVERAGE',
74 'DEF:pred=hw-demo.rrd:in:HWPREDICT',
75 'DEF:conf=hw-demo.rrd:in:DEVPREDICT',
76 'DEF:fail=hw-demo.rrd:in:FAILURES',
77 'TICK:fail#ff8:1:Failures',
78 'CDEF:lowc=pred,conf,2,*,-',
79 'CDEF:widc=conf,4,*',
80 'LINE1:lowc',
81 'AREA:widc#cfc:Band:STACK',
82 'LINE0.1:0#3a1::STACK',
83 'LINE0.1:lowc#3a1',
84 'LINE1:a#c00:InOctets',
85 "LINE1:pred#0a0:Predicted p\\:$period, a\\:$alpha, b\\:$beta\\l";
86 }
88 my ($start,$end) = create ( step => 1800,
89 rows => 16*24*12,
90 period => 24*2,
91 alpha => 0.5,
92 beta => 0.001 );
94 $width=800;
95 $height=100;
96 graph 'HW-input.pdf',
97 '00:00 20080916',
98 'start+14d',
99 'DEF:a=hw-demo.rrd:in:AVERAGE',
100 'LINE2:a#c00:InOctets';
103 $width=450;
104 $height=120;
105 quick 1,0.5,0.001;
106 quick 1,0.1,0.001;
107 quick 1,0.1,0.1;
108 quick 48,0.5,0.001;
109 quick 48,0.2,0.001;
110 quick 48,0.03,0.001;
111 quick 48,0.03,0.1;