Skip to content

Commit

Permalink
Details.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Jan 17, 2025
1 parent 4da7827 commit 87ba074
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ COPY exrc /.exrc
COPY bash.bashrc /etc/bash.bashrc

# A script that can parse our access logs
COPY parse_tomcat_access_log.pl /
COPY parse_tomcat_access_logs.pl /


# some files which might be needed during build
Expand Down
29 changes: 19 additions & 10 deletions parse_tomcat_access_log.pl → parse_tomcat_access_logs.pl
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@


my $dir="/data/logs";
if (scalar(@ARGV) ge 1) {
$dir = $ARGV[0];
}
my $after = "1 week before now";
if (scalar(@ARGV) ge 2) {
$dir = $ARGV[0];
$after = $ARGV[1];
} elsif (scalar(@ARGV) ge 1) {
$after = $ARGV[0];
}

my $findcommand="find $dir -name 'tomcat_access.log*'";
open(FILELIST,"$findcommand |")||die("can't open $findcommand |");
my @filelist=<FILELIST>;
close FILELIST;

my @ignore=('api', 'icons', 'swagger-ui');

my %result=();
for my $file (@filelist) {
print $file;
#print $file;
my $fh;
if ($file =~ /.gz$/) {
open($fh, "gunzip -c $file |") or die $!;
Expand All @@ -36,26 +36,36 @@

my @field=split /\t/;
my $date=$field[0];

if ($date lt $after) {
next;
}
my $client=$field[3];
my $full_client=$field[3];
my $client=(split " ", $full_client)[0];
my $request=$field[7];
my $status=$field[8];
if ($status ge 300) {
next;
}
$request =~ s/^"|"$//g;
my @split_request=split ' ', $request;
my $method=$split_request[0];
if ($method eq 'OPTIONS') {
next;
}
my $full_path=$split_request[1];

my @split_full_path=split /\?/, $full_path;
my $path=$split_full_path[0];
my @split_path=split '/', $path;
my $api=$split_path[3];
if (grep( /^$api$/, @ignore)) {
if (scalar(@split_path) < 4) {
next;
}
my $api="$split_path[0]/$split_path[1]/$split_path[2]/$split_path[3]";

$result{"clients"}{"client=$client"}++;
$result{"methods"}{"method=$method,api=$api"}++;
$result{"api"}{"api=$api"}++;
$result{"status"}{"status=$status"}++;
}
}

Expand All @@ -65,4 +75,3 @@
print ("$name\t$count\t$key\n");
}
}

0 comments on commit 87ba074

Please sign in to comment.