#! /usr/bin/perl # # analysis of directory server access log files # Terry.Gardner@Sun.com # # default values for variables $verbose = "no"; $fc = 0; for($i = 0; $i <= $#ARGV; ++$i) { if("$ARGV[$i]" eq "-v") { $verbose = "yes"; } elsif("$ARGV[$i]" eq "-verbose") { $verbose = "yes"; } else { $access = $ARGV[$i]; } } open(FILE,$access) or die "cannot open $access: $!"; # number of lines in this file $numLines = 0; %closedConnectionsPerSecond=(); %unbindsPerSecond=(); %bindsPerSecond=(); %delsPerSecond=(); %addsPerSecond=(); %srchsPerSecond=(); %modsPerSecond=(); %extPerSecond=(); %resultsPerSecond=(); %newConnectionsPerSecond=(); %keyHash=(); while($line = ) { # increment line count ++$numLines; &parseLine($line); } close FILE; sub printHeader { printf "dd:mmm:yyyy:hh:mm:ss %5s %5s %5s %5s %5s %5s %5s %5s\n","new","closed","binds","unbinds","srchs","mods","adds","exts"; } &printHeader; $line = 1; $interval = 20; foreach $key (sort keys %keyHash) { if($line++ == $interval) { $line = 1; &printHeader; } printf "$key %5d %5d %5d %5d %5d %5d %5d %5d\n",$newConnectionsPerSecond{$key},$closedConnectionsPerSecond{$key},$bindsPerSecond{$key},$unbindsPerSecond{$key},$srchsPerSecond{$key},$modsPerSecond{$key},$addsPerSecond{$key},$extPerSecond{$key}; } # end exit; # display correct invocation sub displayUsage { } # parse a single line from access log sub parseLine { local $_ = $line; #printf; # split the entire line into fields @fields = split(" "); $timeStamp = $fields[0]; $tz = $fields[1]; $c = $fields[2]; $o = $fields[3]; $m = $fields[4]; # change all '/'to ':' and remove the leading space $timeStamp =~ s/\[//g; $timeStamp =~ s/\//:/g; # split the timestamp into fields #@f = split(" ",$timeStamp); #$mday = $f[0]; #$monthName = $f[1]; #$year = $f[2]; #$hour = $f[3]; #$minute = $f[4]; #$second = $f[5]; # create a key from the timestamp #$key = $mday . $monthName . $year . $hour . $minute . $second; $key = $timeStamp; $keyHash{$key} = $key; if(/ closed./) { $closedConnectionsPerSecond{$key}++; } elsif(/ UNBIND/) { $unbindsPerSecond{$key}++; } elsif(/ BIND /) { $bindsPerSecond{$key}++; } elsif(/ DEL /) { $delsPerSecond{$key}++; } elsif(/ ADD /) { $addsPerSecond{$key}++; } elsif(/ SRCH /) { $srchsPerSecond{$key}++; } elsif(/ MOD /) { $modsPerSecond{$key}++; } elsif(/ EXT /) { $extPerSecond{$key}++; } elsif(/ RESULT /) { $resultsPerSecond{$key}++; } elsif(/ connection from /) { $newConnectionsPerSecond{$key}++; } }