📄 tomcat_trend.pl
字号:
#!/usr/local/bin/perl# ========================================================================= # # The Apache Software License, Version 1.1 # # Copyright (c) 1999-2001 The Apache Software Foundation. # All rights reserved. # # ========================================================================= # # Redistribution and use in source and binary forms, with or without modi- # fication, are permitted provided that the following conditions are met: # # 1. Redistributions of source code must retain the above copyright notice # notice, this list of conditions and the following disclaimer. # # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # 3. The end-user documentation included with the redistribution, if any, # must include the following acknowlegement: # # "This product includes software developed by the Apache Software # Foundation <http://www.apache.org/>." # # Alternately, this acknowlegement may appear in the software itself, if # and wherever such third-party acknowlegements normally appear. # # 4. The names "The Jakarta Project", "Jk", and "Apache Software # Foundation" must not be used to endorse or promote products derived # from this software without prior written permission. For written # permission, please contact <apache@apache.org>. # # 5. Products derived from this software may not be called "Apache" nor may # "Apache" appear in their names without prior written permission of the # Apache Software Foundation. # # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL # THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # # ========================================================================= # # This software consists of voluntary contributions made by many indivi- # duals on behalf of the Apache Software Foundation. For more information # on the Apache Software Foundation, please see <http://www.apache.org/>. # # =========================================================================# $Header: /home/cvs/jakarta-tomcat-connectors/jk/tools/reports/tomcat_trend.pl,v 1.3 2002/12/31 04:19:31 glenn Exp $# $Revision: 1.3 $# $Date: 2002/12/31 04:19:31 $# Author: Glenn Nielsen# Script for analyzing mod_jk.log data when logging tomcat request data using# the JkRequestLogFormat Apache mod_jk configuration.## Generates statistics for request latency and errors. Archives the generated# data to files for later use in long term trend graphs and reports.## tomcat_trend.pl <directory containing mod_jk.log> <directory for archiving statistics>use FileHandle;use Statistics::Descriptive;use Time::Local;# Constants%MON = ('JAN' => 0, 'Jan' => 0, 'FEB' => 1, 'Feb' => 1, 'MAR' => 2, 'Mar' => 2, 'APR' => 3, 'Apr' => 3, 'MAY' => 4, 'May' => 4, 'JUN' => 5, 'Jun' => 5, 'JUL' => 6, 'Jul' => 6, 'AUG' => 7, 'Aug' => 7, 'SEP' => 8, 'Sep' => 8, 'OCT' => 9, 'Oct' => 9, 'NOV' => 10, 'Nov' => 10, 'DEC' => 11, 'Dec' => 11,);@Months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");# Check the args$logdir= $ARGV[0];$archivedir = $ARGV[1];die "Usage: $0 logdir archivedir" unless( length($logdir) && length($archivedir) );die "Log Directory $logdir doesn't exist" unless( -d $logdir);die "Archive Directory $archivedir doesn't exist" unless( -d $archivedir);# Get start date from global.data if it existsif( -e "$archivedir/global.data" ) { # Get the start date from the last entry in global.data # print "Checking global.data for startdate\n"; @tail = `tail -1 $archivedir/global.data`; $startdate = (split /\s+/,$tail[0])[0]; ($day, $mon, $year) = (localtime($startdate))[3..5]; $startdate = timelocal(0,0,0,$day+1,$mon,$year);}($day, $mon, $year) = (localtime(time))[3..5];$curdate = timelocal(0,0,0,$day,$mon,$year);print "Today: " . scalar(localtime($curdate)) . "\n";# Get the log files names and date they start@logs = `ls -1 $logdir/mod_jk.log*`;foreach( @logs ) { $logfile = $_; chomp($logfile); next if ( $logfile =~ /\.(bz2|gz|zip)$/ ); @head = `head -1 $logfile`; ($mon, $day, $time, $year) = (split /\s+/,$head[0])[1..4]; ($hour, $min, $sec) = split /:/,$time; $year =~ s/\]$//; # print "$head[0]\n"; # print "$mon $day $time $year $hour $min $sec\n"; $logtime = timelocal($sec,$min,$hour,$day,$MON{$mon},$year-1900); # print "$logfile $logtime " . scalar(localtime($logtime)) . "\n"; $modjklog{$logtime} = $logfile;}# Set the startdate if this is the first time processing the logs# If we have a startdate, remove log files we con't need to processforeach $logtime ( sort {$a <=> $b} keys %modjklog ) { # If logs haven't been processed before, set startdate to time of # first log entry if( $startdate !~ /^\d+$/ ) { $startdate = $logtime; ($day, $mon, $year) = (localtime($startdate))[3..5]; $startdate = timelocal(0,0,0,$day,$mon,$year); last; } if( $logtime > $startdate ) { last; } # Save the previous log file since start date may start here $prevlogfile = $modjklog{$logtime}; $prevlogtime = $logtime; # Remove log files we don't need to process delete $modjklog{$logtime};}# Add back in the previous log file where we need to start processingif( defined $prevlogtime ) { $modjklog{$prevlogtime} = $prevlogfile;}print "StartDate: " . scalar(localtime($startdate)) . "\n";foreach $key ( sort {$a <=> $b} keys %modjklog ) { last if( $key >= $curdate ); $logfile = $modjklog{$key}; $fh = new FileHandle "<$logfile"; die "Open of logfile $logfile failed: $!" unless defined $fh; print "Processing log: $logfile\n"; while( $line = $fh->getline) { chomp($line); ($mon, $day, $time, $year) = (split /\s+/,$line)[1..4]; ($hour, $min, $sec) = split /:/,$time; $year =~ s/\]$//; # print "$mon $day $time $year $hour $min $sec\n"; $logtime = timelocal($sec,$min,$hour,$day,$MON{$mon},$year-1900); if( $logtime > $startdate ) { $origline = $line; # Strip off the leading date and time # print "$line\n"; $line =~ s/^\[.*\] //; # print "$line\n"; # See if this is a new 5 minute period $interval = int($logtime/300); if( $interval != $previnterval ) { if( defined $previnterval ) { &IntervalStats(\%Global,\%Interval,$previnterval*300); } undef %Interval; undef @IntervalLatency; undef %IntervalWorkers; $Interval{tomcat_full} = 0; $Interval{client_gone} = 0; $Interval{latency} = \@IntervalLatency; $Interval{workers} = \%IntervalWorkers; $previnterval = $interval; } # See if this is a new day if( $day != $prevday ) { if( defined $prevday ) { &DailyStats($startdate,\%Global); } undef %Global; undef %GlobalWorkers; undef @GlobalLatency; $Global{tomcat_full} = 0; $Global{client_gone} = 0; $Global{interval} = ""; $Global{latency} = \@GlobalLatency; $Global{workers} = \%GlobalWorkers; $Global{errors} = ""; $prevday = $day; $startdate = $logtime; } # Stop processing if logtime is today
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -