Skip to content

Commit

Permalink
Added a script to parse access logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Jan 17, 2025
1 parent f6cd5a6 commit 1091005
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ COPY exrc /.exrc
# Clean up default /etc/bash.bashrc a bit (no call to groups)
COPY bash.bashrc /etc/bash.bashrc

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


# some files which might be needed during build
ADD clustering /tmp/clustering
Expand Down Expand Up @@ -197,4 +200,3 @@ ONBUILD RUN apt-get update && apt-get -y upgrade && \
(echo "${NAME} version=${PROJECT_VERSION}") >> /DOCKER.BUILD && \
(echo -e "${NAME} git version=${CI_COMMIT_SHA}\t${CI_COMMIT_REF_NAME}\t${CI_COMMIT_TIMESTAMP}\t${CI_COMMIT_TITLE}") >> /DOCKER.BUILD && \
(echo -n "${NAME} build time=" ; date -Iseconds) >> /DOCKER.BUILD

68 changes: 68 additions & 0 deletions parse_tomcat_access_log.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/perl

#we do it in perl, since that's available on ubuntu:latest
# Results can be picked up by nl.vpro.monitoring.binder.ScriptMeterBinder

use strict;
use warnings;


my $dir="/data/logs";
if (scalar(@ARGV) ge 1) {
$dir = $ARGV[0];
}
my $after = "1 week before now";
if (scalar(@ARGV) ge 2) {
$after = $ARGV[1];
}
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;
my $fh;
if ($file =~ /.gz$/) {
open($fh, "gunzip -c $file |") or die $!;
} else {
open($fh, "cat $file |") or die $!;
}

while(<$fh>){

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

if ($date lt $after) {
next;
}
my $client=$field[3];
my $request=$field[7];
$request =~ s/^"|"$//g;
my @split_request=split ' ', $request;
my $method=$split_request[0];
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)) {
next;
}
$result{"clients"}{"client=$client"}++;
$result{"methods"}{"method=$method,api=$api"}++;
$result{"api"}{"api=$api"}++;
}
}


while(my($name, $counts) = each %result) {
while(my($key, $count) = each %$counts) {
print ("$name\t$count\t$key\n");
}
}

0 comments on commit 1091005

Please sign in to comment.