Imported Upstream version 2.4.5
[debian/amanda] / amplot / amplot.awk
1 #
2 # Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 # Copyright (c) 1992-1998, 2000 University of Maryland at College Park
4 # All Rights Reserved.
5 #
6 # Permission to use, copy, modify, distribute, and sell this software and its
7 # documentation for any purpose is hereby granted without fee, provided that
8 # the above copyright notice appear in all copies and that both that
9 # copyright notice and this permission notice appear in supporting
10 # documentation, and that the name of U.M. not be used in advertising or
11 # publicity pertaining to distribution of the software without specific,
12 # written prior permission.  U.M. makes no representations about the
13 # suitability of this software for any purpose.  It is provided "as is"
14 # without express or implied warranty.
15 #
16 # U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 # OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 #
23 # Author: Olafur Gudumundsson, ogud@tis.com
24 # formerly at:     Systems Design and Analysis Group
25 #                  Computer Science Department
26 #                  University of Maryland at College Park
27 #
28 # An awk program to parse the amdump file and output the information
29 # in a form at the gnuplot program amplot.g wants
30 #
31 #       Creation Date: April 1992
32 #       modified: Aug 1993
33 #       Modified for Amanda-2.2: Dec 1993
34 #       Modified for Amanda-2.2: Mar 1994 and May 1994 and June 1994
35 #       Enhanced: April 1995
36 #       Input: One amdump file 
37 #       Output: Number of files that get fed into gnuplot
38 #
39 BEGIN{
40 # The folowing parameters may have to be set to suit each site, both 
41 # parameters are expressed in HOUR's. 
42 # If your average amanda dump is more than 3 hours you should increase the
43 # value of maxtime, similary if your dumps are finishing in less than 2 hours
44 # you should decrease the value of maxtime.
45 # This is now setable from amplot's command line.
46 #       maxtime  = 4;                   # how long to plot graph for in hours
47
48 # Min host controls the reporting of hosts that take long in dumping
49 # This varible can be set explicity or as a fraction of maxtime
50 # If you are seeing too many hosts reported increase the value of this 
51 # constant
52 #
53         min_host = maxtime * 0.75;      # good rule of thumb
54 #       min_host = 2.5;                 # expicit cutoff value in hours
55
56 #
57 # DO NOT CHANGE ANYTHING BELOW THIS LINE
58 #
59         time_scale = 60;        # display in minutes DO NOT CHANGE
60         maxtime  *= time_scale; # convert to minutes
61         min_host *= time_scale *time_scale; # convert to seconds
62                                                 # dumping than this 
63         disk_raise = 120;       # scaling factors for Holding disk graph
64         tape_raise = 90;
65         dump_shift = 7.5;       # scaling factors for Dumpers idle graph
66         dump_raise = 0;
67         que_raise  = 300;       # scaling factors for the queue's
68         count_scale= 1.0/3.0;   # new scale 
69                                 # scaling factors for the x axis 
70         bandw_raise = 250;
71         bandw_scale = 30/300;   # default calculated below 
72
73         holding_disk = -1;      # uninitialized
74                 
75         cnt        = 0;         # default values for counters
76         din        = 0;         # number of dumps to holding disk
77         dout       = 0;         # number of dumps to tape 
78         tapeq      = 0;         # how many dumps in tape queue
79         tape_err   = 0;         # how many tape errors
80         tout       = 0;         # data written out to tape 
81         quit       = 0;         # normal end of run
82         plot_fmt   = "%7.2f %6.2f\n%7.2f %6.2f\n";  # format of files for gnuplot
83         plot_fmt1  = "%7.2f %6.2f\n";  # format of files for gnuplot
84 }
85         
86 {               # state machine for processing input lines lines
87         if( $1 == "driver:") {
88                 if($2=="result")            do_result();
89                 else if( $2=="state")       do_state();
90                 else if( $2=="interface-state") ;
91                 else if( $2=="hdisk-state") do_hdisk++;
92                 else if( $2=="flush" && $3=="size" ) {
93                         flush_size = $4;
94                 }
95                 else if( $2=="start")       do_start();
96                 else if( $2=="send-cmd") { 
97                         if( $7=="FILE-DUMP"){
98                           file_dump++;
99                           dmpr_strt[$6]=$4;
100                           host[$6]=$10;
101                           disk[$6]=$12;
102                           level[$6]=$14;
103                         }
104                         else if( $7 == "FILE-WRITE") file_write++;
105                         else if( $7 == "START-TAPER") fil = $8;
106                 }
107                 else if( $2=="finished-cmd") cmd_fin++;
108                 else if( $2=="started")      forked++;
109                 else if( $2=="QUITTING")     do_quit();
110                 else if( $2=="tape" && $3=="size") ; #eat this line
111                 else if( $2=="dump" && $3=="failed") ; #eat this line
112                 else if( $2=="taper" && $3=="failed") ; #eat this line
113                 else if( $2=="dumping" || $2 == "adding" || $2 == "holding-disks:") 
114                   dumping++; # eat this line
115                 else if( $2!="FINISHED" && $2 != "pid" && $2 != "taper-tryagain"&& $2!="startaflush:")
116                   print fil,"Unknown statement#",$0;
117         }
118         else if ( $1 == "planner:") {
119                 if( $2 == "SKIPPED" || $2 == "FAILED") {
120                         failed++;
121                         print fil, "INFO#", $0;
122                 }
123         }
124         else if( $1 == "GENERATING")        sched_start=NR;
125         else if( $1 == "ENDFLUSH")          sched_start=NR;
126         else if( $1 == "DELAYING")          do_moves();    # find estimated size
127         else if( $1 == "dumper:") {
128                 if($4 != "starting" && $2 != "pid" && $2 != "stream_client:" && $2 != "dgram_bind:") 
129                     print fil, "INFO#", $0;
130         }
131         else if( $1 == "taper:") {
132                 if($3 != "label" && $3 != "end" && $2 != "DONE" && $2 != "pid" && $2 != "slot" && $2 != "reader-side:" && $2 != "page" && $2 != "buffer" && $3 != "at")
133                     print fil, "INFO#", $0;
134         }
135         else if( $1 == "FLUSH") {
136                 no_flush++;
137         }
138         else if( NF==1 && sched_start > 0 && NR-sched_start > 1) { # new style end of schedule
139                 no_disks = NR-sched_start-2; # lets hope there are no extra lines
140                 sched_start = 0;
141         }
142 }
143
144 function do_state(){            # state line is printed out after driver
145                                 # finishes pondering new actions
146                                 # it reports the state as seen be driver
147 # fields in the state line 
148 # $2 = "state"          # $3 = "time"           # $4 = time_val
149 # $5 = "free"           # $6 = "kps:"           # $7 =  free_kps
150 # $8 = "space:"         # $9 = space            # $10 = "taper:"
151 # $11 = "writing"/"idle"# $12 = "idle-dumpers:"
152 # $13 = #idle           # $14 = "qlen"          # $15 = "tapeq:"
153 # $16 = #waiting        # $17 = "runq:"         # $18 = #not started 
154 # $19 = "stoppedq:"     # $20 = #stopped
155
156         cnt++;                                  # number of event
157         time = $4/time_scale;
158         unused = (bandw - $7)*bandw_scale+bandw_raise;
159         if( unused != unused_old) 
160                 printf plot_fmt, time, unused_old, time,unused >>"bandw_free";
161         unused_old = unused;
162
163         if(holding_disk_old != $9) {
164                 disk_alloc_time[disk_a] = time;
165                 disk_alloc_space[disk_a] = holding_disk_old;
166                 disk_a++;
167                 disk_alloc_time[disk_a] = time;
168                 disk_alloc_space[disk_a] = $9;
169                 disk_a++;
170                 holding_disk_old = $9;
171         }
172
173         twait = tsize;
174         if(twait_old != twait) {
175                 twait_time[twait_a] = time;
176                 twait_wait[twait_a] = twait_old;
177                 twait_a++;
178                 twait_time[twait_a] = time;
179                 twait_wait[twait_a] = twait;
180                 twait_a++;
181                 twait_old = twait;
182         }
183
184         active = (dumpers-$13)*dump_shift+dump_raise;
185         if( active != active_old )
186                 printf plot_fmt, time, active_old, time, active >> "dump_idle";
187         active_old = active;
188
189 # tape on or off
190         if($11=="writing")state = tape_raise+10;
191         else              state = tape_raise;
192         if( state != state_old )
193                 printf plot_fmt, time, state_old, time, state >> "tape_idle";
194         state_old = state;
195
196         run = $18*count_scale+que_raise;
197         if( run != run_old )
198                 printf plot_fmt, time, run_old, time, run >> "run_queue";
199         run_old = run;
200
201         finish = written * count_scale+que_raise;
202         if( finish != finish_old )
203                 printf plot_fmt, time, finish_old, time, finish >> "finished";
204         finish_old = finish;
205
206         tapeQ = $16 * count_scale+que_raise;
207         if( tapeQ != tapeQ_old )
208                 printf plot_fmt, time, tapeQ_old, time, tapeQ >> "tape_queue";
209         tapeQ_old = tapeQ;
210
211 }
212
213 function do_start() {           # get configuration parameters
214         dumpers    = $6;        # how many 
215         day        = $14;
216         dump_shift = 75/dumpers; 
217         bandw      = $8;                
218         bandw_scale = (30/bandw);
219         unused_old = bandw_raise;
220         print 0, unused_old > "bandw_free";
221         if( sched_start >0 ) {
222                 no_disks = NR-sched_start-1; # backward compatability
223                 sched_start =0;
224                 print "do_start: no_disks", no_disks, $0;
225         }
226         no_disks += no_flush;
227         size        = $10/1024;        # size of holding disk in MB
228         holding_disk= $10 + flush_size;
229         init_holding_disk= $10 + flush_size;
230         holding_disk_old = $10;
231         disk_a = 0;
232         disk_alloc_time[disk_a] = 0;
233         disk_alloc_space[disk_a] = holding_disk_old;
234         disk_a++;
235         tsize = flush_size;
236         twait_old = tsize;
237         twait_a = 0;
238         twait_time[twait_a] = 0;
239         twait_wait[twait_a] = twait_old;
240         twait_a++;
241         if( NF==14) {           # original file was missing this
242                 policy="FIFO";
243                 alg   ="InOrder";
244         }
245         else if(NF>=18) {               # newer files have this format
246                 policy = $18;
247                 alg = $16;
248                 if( alg=="drain-ends") big = $20; 
249         }
250         
251         start = $4;     # this is the start time of the first dump 
252                         # taper idle to this point should not be included
253         run_old = no_disks*cont_scale+que_raise;
254         print 0, run_old                >"run_queue";
255         finish_old = tapeQ_old = que_raise;
256         print 0, finish_old             >"finished";    
257         print 0, tapeQ_old              >"tape_queue" ; 
258         state_old = tape_raise;
259         print 0, state_old              > "tape_idle";
260         active_old = dump_raise;
261         print 0,active_old              >"dump_idle";
262
263 }
264
265 function do_quit(){             # this is issued by driver at the end
266                                 # when it has nothing more to do
267         cnt++;
268         quit = 1;
269         tim  = $4 / time_scale;
270
271         disk_alloc_time[disk_a] = tim;
272         disk_alloc_space[disk_a] = holding_disk_old;
273         disk_a++;
274         max_space=disk_alloc_space[0];
275         for(a=0; a<disk_a; a++) {
276                 if(disk_alloc_space[a] > max_space) {
277                         max_space = disk_alloc_space[a];
278                 }
279         }
280
281         space_change = 0;
282         if(max_space > holding_disk) {
283                 space_change = max_space - holding_disk;
284                 holding_disk = max_space;
285         }
286
287         twait_time[twait_a] = tim;
288         twait_wait[twait_a] = twait_old;
289         twait_a++;
290         min_wait=twait_wait[0];
291         for(a=0; a<twait_a; a++) {
292                 if(twait_wait[a] < min_wait) {
293                         min_wait = twait_wait[a];
294                 }
295         }
296         if(min_wait < 0) {
297                 if(flush_size == 0) {
298                         holding_disk -= min_wait;
299                         holding_disk -= space_change;
300                 }
301                 for(a=0; a<twait_a; a++) {
302                         twait_wait[a] -= min_wait;
303                 }
304         }
305         if (holding_disk != 0) {
306                 const = 100/holding_disk;
307         }
308         else {
309                 const = 100;
310         }
311         for(a=0; a<disk_a; ++a) {
312                 space = (holding_disk - disk_alloc_space[a])*const+disk_raise
313                 printf plot_fmt1, disk_alloc_time[a], space >> "disk_alloc";
314         }
315         for(a=0; a<twait_a; ++a) {
316                 space = (twait_wait[a])*const+disk_raise
317                 printf plot_fmt1, twait_time[a], space >> "tape_wait";
318         }
319
320         printf plot_fmt, tim, active_old, tim, dump_raise >>"dump_idle";
321         printf plot_fmt, tim, state_old, tim, tape_raise >>"tape_idle"; 
322         printf plot_fmt, tim, unused_old, tim, bandw_raise >>"bandw_free";
323         printf plot_fmt, tim, finish_old, tim, written*count_scale+que_raise >>"finished";
324         printf plot_fmt, tim, run_old, tim, run_old >>"run_queue";
325 }
326
327 function do_result(){           # process lines driver: result
328         if($7=="DONE" ) {
329                 if( $6=="taper:"){              # taper done
330                         tsize -= $14;   
331                         tout  += $14;
332                         tcnt--; written++;
333                 }
334                 else {                          # dumperx done 
335                   tsize += (int($15/32)+1)*32;  # in tape blocks 
336                   tcnt++;       done++;
337                   xx = host[$6];
338                   d = disk[$6];
339                   l = level[$6];
340                   host_time[xx]+= ( tt = $4 - dmpr_strt[$6]);
341                   if(xx in disk_list) disk_list[xx] = disk_list[xx] "\n";
342                   disk_list[xx] = disk_list[xx] \
343                                   xx ":" d "/" l "\t" \
344                                   pr_time(dmpr_strt[$6]) \
345                                   " - " pr_time($4) \
346                                   " = "  pr_time(tt);
347 #                 print host[$6], disk[host[$6]];
348 #                       print host[$6], $4, dmpr_strt[$6], host_time[host[$6]]
349                 }
350         }
351         else if ($6=="taper:") {                # something else than DONE
352                 if($7=="TAPE-ERROR" || $7=="TRY-AGAIN") {
353                         tape_err= 1;
354                         err_time=$4/time_scale;
355                 }
356                 else if ($7=="TAPER-OK") tape_err=0;
357                 else if ($7=="PORT")    tape_err=0;
358                 else print fil, "UNKNOWN STATUS# "$0 ;
359         }
360         else {                                  # something bad from dumper 
361                 if ($7=="FAILED") { failed++;}
362                 else if ($7=="TRY-AGAIN"){ try++;}
363                 else if ($7=="RQ-MORE-DISK") ;  # FIXME: ignore for now
364                 else if ($7=="NO-ROOM")  
365                   print fil, pr_time($4),"#"  ++no_room, $0;
366                 else if( $7=="ABORT-FINISHED") print fil, "#" ++no_abort, $0;
367                 else print fil, "UNKNOWN STATUS# " $0;
368         }
369 }
370
371 function do_moves() { # function that extracts the estimated size of dumps
372                       # by processing DELAYING and promoting lines
373         est_size=$6;
374         getline ;                       # eat get next line print out planner msg
375         while (NF > 0 && (($1 == "delay:") || ($1 == "planner:")) ) {
376           if( $1 == "delay:") est_size = $NF;   # processing delay lines
377           else print fil, "DELAY#", $0;
378           getline;
379         }
380         getline ;                       # eating blank line
381         if( $1== "PROMOTING") {         # everything is dandy 
382                 getline;                # get first promote line
383                 while ( NF>0 && ($1 == "promote:" || $1 == "planner:" || $1 == "no" || $1 == "try") ) {
384                         if( $2 == "moving") {
385                                 est_size=$8;
386                                 print fil, "PROMOTING#", $1, $3;
387                         }
388                         else if($2 != "checking" && $2 != "can't" && $3 != "too" &&  $1 != "no" && $1 != "try" && $2 != "time")
389                              print fil,"PROMOTING#", $0;
390                         getline ;       # get next promote line
391                 }
392         }
393         else print fil, "DID NOT FIND PROMOTING LINE IN THE RIGHT PLACE",NR,$0;
394 }
395
396
397 END {
398         if( holding_disk == -1) {               # bad input file 
399                 print fil,": MISSING SPACE DECLARATION" ;
400                 exit;
401         }
402 # print headers of each graph  this is for the gnulot version 
403         if( tim >maxtime && extend==0)# if graph will extend beond borders
404           printf "Graph extends beond borders %s taking %7.3f > (max = %7.3f)\n",
405                         fil, tim, maxtime ;
406         print_t();                      # print titles
407         if( no_room + no_abort > 0) 
408              printf "NO-ROOM=%5d ABORT-FINISHED=%5d\n",  no_room, no_abort;
409         max_out = 20;
410         old_t = min_host * min_host;  # Some thing big
411         print "Longest dumping hosts   Times", min_host;
412         print "Host:disk/lev  \t start  -   end   =   run\t=> total";
413         while ( max_out-- > 0 && old_t > min_host) {
414           t = 0;
415           for (j in host_time) {
416             if( t < host_time[j] && host_time[j] <old_t){
417               t = host_time[d=j];
418             }
419           }
420           printf "%s\t=> %s\n\n", disk_list[d], pr_time(host_time[d]);
421 #         printf "%-20.20s Total Dump time %s\n", d, pr_time(host_time[d]);
422           old_t = t;
423         }
424 }
425
426 function print_t(){             # printing out the labels for the graph 
427         label=0;                # calculating where labels go and 
428                                 # range for x and y axes
429         maxy = int(no_disks/60+1)*20+que_raise;
430         printf "set yrange[0:%d]\n",maxy >"title";
431         if( maxtime < tim && extend !=0) {
432                 printf "set xrange[0:%d]\n", tim+30 >>"title";
433                 second_col = tim*0.5;
434                 key_col = tim;
435                 third_col = tim +13;
436         }
437         else {
438                 printf "set xrange[0:%d]\n", maxtime >>"title";
439                 second_col = (maxtime-10) * 0.5;
440                 key_col = (maxtime-10) ;
441                 third_col = maxtime +3;
442         }
443         label_shift = (7 + int(no_disks/100));
444         lab = label_start = maxy+(6*label_shift) ;  # showing 6 labels
445         printf "set key %d, %d\n", key_col, lab >>"title";
446         printf "set label %d \"Amanda Dump %s\" at 10,%d\n", ++label,fil, 
447                 lab >"title";
448         lab -= label_shift;
449         printf "set label %d \"Bandwidth = %d\" at 10,%d\n",++label,bandw,
450                 lab >>"title";
451
452         lab -= label_shift;
453         printf "set label %d \"Holding disk = %d\" at 10,%d\n",++label,size,
454                 lab >>"title";
455
456         lab -= label_shift;
457         printf "set label %d \"Tape Policy = %s\" at 10,%d\n",++label,policy,
458                 lab >>"title";
459
460         lab -= label_shift;
461         printf "set label %d \"Dumpers= %d\" at 10,%d\n",++label,dumpers,
462                 lab >>"title";
463
464         lab -= label_shift;
465         if( alg =="drain-ends") 
466                 printf "set label %d \"Driver alg = %s At big end %d\" at 10,%d\n",
467                         ++label,alg, big,lab >>"title";
468         else #if( alg =="InOrder")  # other special cases
469                 printf "set label %d \"Driver alg = %s\" at 10,%d\n",
470                         ++label,alg, lab >>"title";
471
472         lab = label_start;
473         printf "set label %d \"Elapsed Time = %s\" at %d,%d\n",
474                 ++label,pr_time(tim*60),second_col,lab >>"title";
475
476         lab -= label_shift;
477         if( tape_err==1)        stm = "TAPE ERROR";
478         else if( quit ==1)      stm = "SUCCESS";
479         else  {                 stm = "UNKNOWN";
480                 print "Unknown terminating status",fil;
481         }
482         printf "set label %d \"Final status = %s\" at %d,%d\n",
483                 ++label,stm, second_col,lab >> "title";
484
485         lab -= label_shift;
486         printf "set label %d \"Dumped/Failed = %3d/%d\" at %d,%d\n",
487                 ++label,done,(failed+(try/2)), second_col,lab >>"title";
488
489         lab -= label_shift; 
490         printf "set label %d \"Output data size = %d\" at %d, %d\n",
491                 ++label,int(tout/1024+0.49999),second_col,lab >>"title";
492         if( est_size >0) {
493                 lab -= label_shift; 
494                 printf "set label %d \"Estimated data size = %d\" at %d, %d\n",
495                         ++label,int(est_size/1024+0.49999),second_col,lab >>"title";
496         }
497
498         if (gnuplot==0) {
499                 printf "set output \"%s.ps\"\n",fil >>"title";
500                 if(bw==1) {
501                         if(paper==1) printf "set term postscript landscape \"Times-Roman\" 10\n" >>"title";
502                         else printf "set term postscript portrait \"Times-Roman\" 10\n" >>"title";
503                 }
504                 else {
505                         if(paper==1) printf "set term postscript landscape color \"Times-Roman\" 10\n" >>"title";
506                         else printf "set term postscript portrait color \"Times-Roman\" 10\n" >>"title";
507                 }
508         }
509         printf "set ylabel """";" >>"title";    # make sure there is no ylabel
510         fmt= "set label %d \"%s\" at "third_col", %d\n";
511         printf fmt, ++label,"%DUMPERS", 40 >>"title";
512         printf fmt, ++label,"TAPE",  95 >>"title";
513         printf fmt, ++label,"HOLDING",180 >>"title";
514         printf fmt, ++label,"DISK", 160 >>"title";
515         printf fmt, ++label,"%BANDWIDTH", 260 >>"title";
516         printf fmt, ++label,"QUEUES",(que_raise+maxy)/2 >>"title";
517         if((paper+gnuplot) > 0) print "set size 0.9, 0.9;"  >>"title";
518         else                    print "set size 0.7,1.3;"   >>"title";
519 }
520
521 function pr_time(pr_a){ #function to pretty print time
522   pr_h = int(pr_a/3600);
523   pr_m = int(pr_a/60)%60;
524   pr_s = int(pr_a+0.5) %60;
525   if( pr_m < 10 && pr_s < 10 ) return  pr_h":0"pr_m":0"pr_s;
526   else if( pr_s < 10)          return  pr_h":" pr_m":0"pr_s;
527   else if( pr_m < 10)          return  pr_h":0"pr_m":" pr_s;
528   else                         return  pr_h":" pr_m":" pr_s;
529 }