bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / tomcat-connectors-1.2.32-src / tools / reports / tomcat_reports.pl
1 #!/usr/local/bin/perl
2
3 #
4 # Licensed to the Apache Software Foundation (ASF) under one or more
5 # contributor license agreements.  See the NOTICE file distributed with
6 # this work for additional information regarding copyright ownership.
7 # The ASF licenses this file to You under the Apache License, Version 2.0
8 # (the "License"); you may not use this file except in compliance with
9 # the License.  You may obtain a copy of the License at
10 #
11 #    http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 # $Id: tomcat_reports.pl 466585 2006-10-21 22:16:34Z markt $
21
22 # Author: Glenn Nielsen
23
24 # Script for generating reports and graphs using statistical data generated
25 # by the tomcat_trend.pl script.
26 #
27 # The following graphs are created:
28 #
29 #  tomcat_request.png
30 #    Long term trend graph of total number of tomcat requests handled
31 #
32 #  tomcat_median.png
33 #    Long term overall trend graph of tomcat request latency median
34 #
35 #  tomcat_deviation.png
36 #    Long term overall trend graph of tomcat request mean and standard deviation
37 #
38 #  tomcat_error.png
39 #    Long term trend graph of requests rejected by tomcat. Shows requests rejected
40 #    when tomcat has no request processors available.  Can be an indicator that tomcat
41 #    is overloaded or having other scaling problems.
42 #
43 #  tomcat_client.png
44 #    Long term trend graph of requests forward to tomcat which were aborted by the remote
45 #    client (browser).  You will normally see some aborted requests.  High numbers of these
46 #    can be an indicator that tomcat is overloaded or there are requests which have very high
47 #    latency.
48 #
49 # tomcat_reports.pl <directory where statistics are archived> <directory to place graphs/reports in>
50
51 use GD;
52 use GD::Graph;
53 use GD::Graph::Data;
54 use GD::Graph::lines;
55 use GD::Graph::linespoints;
56 use Statistics::Descriptive;
57 use Time::Local;
58
59 # Constants
60
61 %MON = ('JAN' => 0, 'Jan' => 0,
62         'FEB' => 1, 'Feb' => 1,
63         'MAR' => 2, 'Mar' => 2,
64         'APR' => 3, 'Apr' => 3,
65         'MAY' => 4, 'May' => 4,
66         'JUN' => 5, 'Jun' => 5,
67         'JUL' => 6, 'Jul' => 6,
68         'AUG' => 7, 'Aug' => 7,
69         'SEP' => 8, 'Sep' => 8,
70         'OCT' => 9, 'Oct' => 9,
71         'NOV' => 10, 'Nov' => 10,
72         'DEC' => 11, 'Dec' => 11,);
73
74 @Months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
75
76 # Check the args
77
78 $archivedir = $ARGV[0];
79 $reportdir = $ARGV[1];
80
81 die "Usage: $0 archivedir reportdir"
82    unless( length($archivedir) && ($reportdir) );
83
84 die "Archive Directory $archivedir doesn't exist"
85    unless( -d $archivedir);
86
87 die "Report Directory $reportdir doesn't exist"
88    unless( -d $reportdir);
89
90 # Read in data from file
91 die "Archive Directory $archivedir has no global.data file"
92    unless( -e "$archivedir/global.data" );
93
94 @Data = `tail -365 $archivedir/global.data`;
95 $numdays = $#Data;
96 $daycounter = $numdays;
97
98 foreach( @Data ) {
99    $line = $_;
100    chomp($line);
101    ($date,$count,$median,$mean,$stddev,$min,$max,$client_gone,$tomcat_full) = split /\s+/,$line;
102    # print "$daycounter $date $count $median $mean $stdev $min $max $client_gone $tomcat_full\n";
103    $start_time = $date unless $start_time>0;
104    $end_time = $date;
105    push @days,int($daycounter/7);
106    push @count,$count;
107    push @median,$median;
108    push @mean,$mean;
109    push @stddev,$mean+$stddev;
110    push @min,$min;
111    push @max,$max;
112    push @client_gone,$client_gone;
113    push @tomcat_full,$tomcat_full;
114    $daycounter--;
115 }
116
117 ($day,$mon,$year) = (localtime($start_time))[3..5];
118 $year += 1900;
119 $startdate = "$Months[$mon] $day, $year";
120 ($day,$mon,$year) = (localtime($end_time))[3..5];
121 $year += 1900;
122 $enddate = "$Months[$mon] $day, $year";
123
124 # Output request trend graph
125 $outfile = "$reportdir/tomcat_request.png";
126 unlink $outfile;
127
128 $stats = Statistics::Descriptive::Sparse->new();
129 $stats->add_data(@count);
130 $max = $stats->max();
131 $min = $stats->min();
132
133 &RequestGraph();
134
135 # Output median latency trend graph
136 $outfile = "$reportdir/tomcat_median.png";
137 unlink $outfile;
138
139 $stats = Statistics::Descriptive::Sparse->new();
140 $stats->add_data(@median);
141 $max = $stats->max();
142 $min = $stats->min();
143
144 &MedianGraph();
145
146 # Output latency deviation trend graph
147 $outfile = "$reportdir/tomcat_deviation.png";
148 unlink $outfile;
149
150 $stats = Statistics::Descriptive::Sparse->new();
151 $stats->add_data(@stddev);
152 $stats->add_data(@mean);
153 $max = $stats->max();
154 $min = $stats->min();
155
156 &DeviationGraph();
157
158 # Output request error trend graph
159 $outfile = "$reportdir/tomcat_error.png";
160 unlink $outfile;
161
162 $stats = Statistics::Descriptive::Sparse->new();
163 $stats->add_data(@tomcat_full);
164 $max = $stats->max();
165 $min = $stats->min();
166
167 &ErrorGraph();
168
169 # Output request error trend graph
170 $outfile = "$reportdir/tomcat_client.png";
171 unlink $outfile;
172
173 $stats = Statistics::Descriptive::Sparse->new();
174 $stats->add_data(@client_gone);
175 $max = $stats->max();
176 $min = $stats->min();
177
178 &ClientGraph();
179
180 exit;
181
182 sub RequestGraph {
183
184   $graph = GD::Graph::lines->new(800,600);
185   @data = (\@days,\@count);
186
187   $div = 100;
188   $div = 500 if $max >= 2000;
189   $div = 1000 if $max >= 5000;
190   $div = 5000 if $max >= 20000;
191   $div = 10000 if $max >= 50000;
192   $div = 50000 if $max >= 200000;
193   $div = 100000 if $max >= 500000;
194   $div = 500000 if $max >= 2000000;
195   $div = 1000000 if $max >= 5000000;
196   $ymax = (int($max/$div) + 1)*$div;
197   $ymin = int($min/$div)*$div;
198   $ytick = ($ymax - $ymin)/$div;
199
200   $graph->set(
201     y_label             => 'Requests',
202     title               => "Tomcat Requests by Day from $startdate to $enddate",
203     y_min_value         => $ymin,
204     y_max_value         => $ymax,
205     y_tick_number       => $ytick,
206     y_number_format     => \&val_format,
207     x_label             => 'Weeks Ago',
208     x_label_skip        => 7,
209     x_tick_offset       => $numdays%7,
210     dclrs               => [ qw(green) ],
211     legend_placement    => 'BC'
212   ) or warn $graph->error;
213
214   $graph->set_legend( 'Requests' );
215   $graph->set_title_font(GD::gdGiantFont);
216   $graph->set_x_axis_font(GD::gdSmallFont);
217   $graph->set_y_axis_font(GD::gdSmallFont);
218   $graph->set_legend_font(GD::gdSmallFont);
219   $gd = $graph->plot(\@data);
220   die "Graph Plot Failed: " . $graph->error unless defined $gd;
221
222   open IMG, ">$outfile" or die $!;
223   print IMG $gd->png or die $gd->error;
224   close IMG;
225 }
226
227 sub MedianGraph {
228
229   $graph = GD::Graph::lines->new(800,600);
230   @data = (\@days,\@median);
231
232   $div = .05;
233   $div = .1 if $max >= .5;
234   $div = .5 if $max >= 2;
235   $div = 1 if $max >= 5;
236   $div = 5 if $max >= 20;
237   $div = 10 if $max >= 50;
238   $div = 50 if $max >= 200;
239   $div = 100 if $max >= 500;
240   $ymax = (int($max/$div) + 1)*$div;
241   $ytick = $ymax/$div;
242
243   $graph->set(
244     y_label             => 'Latency (Seconds)',
245     title               => "Tomcat Request Median Latency by Day from $startdate to $enddate",
246     y_min_value         => 0,
247     y_max_value         => $ymax,
248     y_tick_number       => $ytick,
249     y_number_format     => \&val_format,
250     x_label             => 'Weeks Ago',
251     x_label_skip        => 7,
252     x_tick_offset       => $numdays%7,
253     dclrs               => [ qw(green) ],
254     legend_placement    => 'BC'
255   ) or warn $graph->error;
256
257   $graph->set_legend( 'Median' );
258   $graph->set_title_font(GD::gdGiantFont);
259   $graph->set_x_axis_font(GD::gdSmallFont);
260   $graph->set_y_axis_font(GD::gdSmallFont);
261   $graph->set_legend_font(GD::gdSmallFont);
262   $gd = $graph->plot(\@data);
263   die "Graph Plot Failed: " . $graph->error unless defined $gd;
264
265   open IMG, ">$outfile" or die $!;
266   print IMG $gd->png or die $gd->error;
267   close IMG;
268 }
269
270 sub DeviationGraph {
271
272   $graph = GD::Graph::lines->new(800,600);
273   @data = (\@days,\@mean,\@stddev);
274
275   $div = .1;
276   $div = .5 if $max >= 2;
277   $div = 1 if $max >= 5;
278   $div = 5 if $max >= 20;
279   $div = 10 if $max >= 50;
280   $div = 50 if $max >= 200;
281   $div = 100 if $max >= 500;
282   $ymax = (int($max/$div) + 1)*$div;
283   $ytick = $ymax/$div;
284
285   $graph->set(
286     y_label             => 'Latency (Seconds)',
287     title               => "Tomcat Request Latency Mean and Deviation by Day from $startdate to $enddate",
288     y_max_value         => $ymax,
289     y_tick_number       => $ytick,
290     x_label             => 'Weeks Ago',
291     x_label_skip        => 7,
292     x_tick_offset       => $numdays%7,
293     dclrs               => [ qw(green yellow) ],
294     legend_placement    => 'BC'
295   ) or warn $graph->error;
296
297   $graph->set_legend( 'Mean', 'Mean plus Standard Deviation' );
298   $graph->set_title_font(GD::gdGiantFont);
299   $graph->set_x_axis_font(GD::gdSmallFont);
300   $graph->set_y_axis_font(GD::gdSmallFont);
301   $graph->set_legend_font(GD::gdSmallFont);
302   $gd = $graph->plot(\@data);
303   die "Graph Plot Failed: " . $graph->error unless defined $gd;
304
305   open IMG, ">$outfile" or die $!;
306   print IMG $gd->png or die $gd->error;
307   close IMG;
308 }
309
310 sub ErrorGraph {
311
312   $graph = GD::Graph::lines->new(800,600);
313   @data = (\@days,\@tomcat_full);
314
315   $div = 5;
316   $div = 10 if $max >=100;
317   $div = 50 if $max >= 200;
318   $div = 100 if $max >= 1000;
319   $div = 500 if $max >= 2000;
320   $div = 1000 if $max >= 5000;
321   $div = 5000 if $max >= 20000;
322   $div = 10000 if $max >= 50000;
323   $div = 50000 if $max >= 200000;
324   $div = 100000 if $max >= 500000;
325   $div = 500000 if $max >= 2000000;
326   $div = 1000000 if $max >= 5000000;
327   $ymax = (int($max/$div) + 1)*$div;
328   $ymin = int($min/$div)*$div;
329   $ytick = ($ymax - $ymin)/$div;
330
331   $graph->set(
332     y_label             => 'Requests',
333     title               => "Tomcat Rejected Request by Day from $startdate to $enddate",
334     y_min_value         => $ymin,
335     y_max_value         => $ymax,
336     y_tick_number       => $ytick,
337     y_number_format     => \&val_format,
338     x_label             => 'Weeks Ago',
339     x_label_skip        => 7,
340     x_tick_offset       => $numdays%7,
341     dclrs               => [ qw(green) ],
342     legend_placement    => 'BC'
343   ) or warn $graph->error;
344
345   $graph->set_legend( 'Tomcat Rejected Requests' );
346   $graph->set_title_font(GD::gdGiantFont);
347   $graph->set_x_axis_font(GD::gdSmallFont);
348   $graph->set_y_axis_font(GD::gdSmallFont);
349   $graph->set_legend_font(GD::gdSmallFont);
350   $gd = $graph->plot(\@data);
351   die "Graph Plot Failed: " . $graph->error unless defined $gd;
352
353   open IMG, ">$outfile" or die $!;
354   print IMG $gd->png or die $gd->error;
355   close IMG;
356 }
357
358 sub ClientGraph {
359
360   $graph = GD::Graph::lines->new(800,600);
361   @data = (\@days,\@client_gone);
362
363   $div = 5;
364   $div = 10 if $max >=100;
365   $div = 50 if $max >= 200;
366   $div = 100 if $max >= 1000;
367   $div = 500 if $max >= 2000;
368   $div = 1000 if $max >= 5000;
369   $div = 5000 if $max >= 20000;
370   $div = 10000 if $max >= 50000;
371   $div = 50000 if $max >= 200000;
372   $div = 100000 if $max >= 500000;
373   $div = 500000 if $max >= 2000000;
374   $div = 1000000 if $max >= 5000000;
375   $ymax = (int($max/$div) + 1)*$div;
376   $ymin = int($min/$div)*$div;
377   $ytick = ($ymax - $ymin)/$div;
378
379   $graph->set(
380     y_label             => 'Requests',
381     title               => "Tomcat Client Aborted Requests by Day from $startdate to $enddate",
382     y_min_value         => $ymin,
383     y_max_value         => $ymax,
384     y_tick_number       => $ytick,
385     y_number_format     => \&val_format,
386     x_label             => 'Weeks Ago',
387     x_label_skip        => 7,
388     x_tick_offset       => $numdays%7,
389     dclrs               => [ qw(green) ],
390     legend_placement    => 'BC'
391   ) or warn $graph->error;
392
393   $graph->set_legend( 'Tomcat Client Aborted Requests' );
394   $graph->set_title_font(GD::gdGiantFont);
395   $graph->set_x_axis_font(GD::gdSmallFont);
396   $graph->set_y_axis_font(GD::gdSmallFont);
397   $graph->set_legend_font(GD::gdSmallFont);
398   $gd = $graph->plot(\@data);
399   die "Graph Plot Failed: " . $graph->error unless defined $gd;
400
401   open IMG, ">$outfile" or die $!;
402   print IMG $gd->png or die $gd->error;
403   close IMG;
404 }
405
406 sub val_format {
407   my $value = shift;
408   my $ret;
409
410   $ret = $value;
411   if( $ret =~ /\./ ) {
412     $ret =~ s/\.(\d\d\d).*/\.$1/;
413   } else {
414     $ret =~ s/(\d+)(\d\d\d)$/$1,$2/;
415     $ret =~ s/(\d+)(\d\d\d),(\d\d\d)$/$1,$2,$3/;
416   }
417   return $ret;
418 }
419
420 sub size_format {
421   my $value = shift;
422   my $ret;
423
424   if( $max >= 5000 ) {
425      $value = int(($value/1024)+.5);
426   }
427   $ret = $value;
428   $ret =~ s/(\d+)(\d\d\d)$/$1,$2/;
429   $ret =~ s/(\d+)(\d\d\d),(\d\d\d)$/$1,$2,$3/;
430   return $ret;
431 }