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
11 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 # $Id: tomcat_reports.pl 466585 2006-10-21 22:16:34Z markt $
22 # Author: Glenn Nielsen
24 # Script for generating reports and graphs using statistical data generated
25 # by the tomcat_trend.pl script.
27 # The following graphs are created:
30 # Long term trend graph of total number of tomcat requests handled
33 # Long term overall trend graph of tomcat request latency median
35 # tomcat_deviation.png
36 # Long term overall trend graph of tomcat request mean and standard deviation
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.
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
49 # tomcat_reports.pl <directory where statistics are archived> <directory to place graphs/reports in>
55 use GD::Graph::linespoints;
56 use Statistics::Descriptive;
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,);
74 @Months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
78 $archivedir = $ARGV[0];
79 $reportdir = $ARGV[1];
81 die "Usage: $0 archivedir reportdir"
82 unless( length($archivedir) && ($reportdir) );
84 die "Archive Directory $archivedir doesn't exist"
85 unless( -d $archivedir);
87 die "Report Directory $reportdir doesn't exist"
88 unless( -d $reportdir);
90 # Read in data from file
91 die "Archive Directory $archivedir has no global.data file"
92 unless( -e "$archivedir/global.data" );
94 @Data = `tail -365 $archivedir/global.data`;
96 $daycounter = $numdays;
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;
105 push @days,int($daycounter/7);
107 push @median,$median;
109 push @stddev,$mean+$stddev;
112 push @client_gone,$client_gone;
113 push @tomcat_full,$tomcat_full;
117 ($day,$mon,$year) = (localtime($start_time))[3..5];
119 $startdate = "$Months[$mon] $day, $year";
120 ($day,$mon,$year) = (localtime($end_time))[3..5];
122 $enddate = "$Months[$mon] $day, $year";
124 # Output request trend graph
125 $outfile = "$reportdir/tomcat_request.png";
128 $stats = Statistics::Descriptive::Sparse->new();
129 $stats->add_data(@count);
130 $max = $stats->max();
131 $min = $stats->min();
135 # Output median latency trend graph
136 $outfile = "$reportdir/tomcat_median.png";
139 $stats = Statistics::Descriptive::Sparse->new();
140 $stats->add_data(@median);
141 $max = $stats->max();
142 $min = $stats->min();
146 # Output latency deviation trend graph
147 $outfile = "$reportdir/tomcat_deviation.png";
150 $stats = Statistics::Descriptive::Sparse->new();
151 $stats->add_data(@stddev);
152 $stats->add_data(@mean);
153 $max = $stats->max();
154 $min = $stats->min();
158 # Output request error trend graph
159 $outfile = "$reportdir/tomcat_error.png";
162 $stats = Statistics::Descriptive::Sparse->new();
163 $stats->add_data(@tomcat_full);
164 $max = $stats->max();
165 $min = $stats->min();
169 # Output request error trend graph
170 $outfile = "$reportdir/tomcat_client.png";
173 $stats = Statistics::Descriptive::Sparse->new();
174 $stats->add_data(@client_gone);
175 $max = $stats->max();
176 $min = $stats->min();
184 $graph = GD::Graph::lines->new(800,600);
185 @data = (\@days,\@count);
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;
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',
209 x_tick_offset => $numdays%7,
210 dclrs => [ qw(green) ],
211 legend_placement => 'BC'
212 ) or warn $graph->error;
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;
222 open IMG, ">$outfile" or die $!;
223 print IMG $gd->png or die $gd->error;
229 $graph = GD::Graph::lines->new(800,600);
230 @data = (\@days,\@median);
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;
244 y_label => 'Latency (Seconds)',
245 title => "Tomcat Request Median Latency by Day from $startdate to $enddate",
247 y_max_value => $ymax,
248 y_tick_number => $ytick,
249 y_number_format => \&val_format,
250 x_label => 'Weeks Ago',
252 x_tick_offset => $numdays%7,
253 dclrs => [ qw(green) ],
254 legend_placement => 'BC'
255 ) or warn $graph->error;
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;
265 open IMG, ">$outfile" or die $!;
266 print IMG $gd->png or die $gd->error;
272 $graph = GD::Graph::lines->new(800,600);
273 @data = (\@days,\@mean,\@stddev);
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;
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',
292 x_tick_offset => $numdays%7,
293 dclrs => [ qw(green yellow) ],
294 legend_placement => 'BC'
295 ) or warn $graph->error;
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;
305 open IMG, ">$outfile" or die $!;
306 print IMG $gd->png or die $gd->error;
312 $graph = GD::Graph::lines->new(800,600);
313 @data = (\@days,\@tomcat_full);
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;
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',
340 x_tick_offset => $numdays%7,
341 dclrs => [ qw(green) ],
342 legend_placement => 'BC'
343 ) or warn $graph->error;
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;
353 open IMG, ">$outfile" or die $!;
354 print IMG $gd->png or die $gd->error;
360 $graph = GD::Graph::lines->new(800,600);
361 @data = (\@days,\@client_gone);
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;
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',
388 x_tick_offset => $numdays%7,
389 dclrs => [ qw(green) ],
390 legend_placement => 'BC'
391 ) or warn $graph->error;
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;
401 open IMG, ">$outfile" or die $!;
402 print IMG $gd->png or die $gd->error;
412 $ret =~ s/\.(\d\d\d).*/\.$1/;
414 $ret =~ s/(\d+)(\d\d\d)$/$1,$2/;
415 $ret =~ s/(\d+)(\d\d\d),(\d\d\d)$/$1,$2,$3/;
425 $value = int(($value/1024)+.5);
428 $ret =~ s/(\d+)(\d\d\d)$/$1,$2/;
429 $ret =~ s/(\d+)(\d\d\d),(\d\d\d)$/$1,$2,$3/;