Skip to content

Commit 75af847

Browse files
committed
Details.
1 parent fb50b37 commit 75af847

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
.DEFAULT_GOAL := docker
2+
3+
.PHONY: exec access_logs
24
IMAGE := vpro/tomcat:dev
35

46
help: ## Show this help.
@@ -19,3 +21,6 @@ exec: ## Look around in the build image
1921

2022
exectest:
2123
docker run -it --entrypoint /bin/bash vpro/test:latest
24+
25+
access_logs:
26+
docker run -it --entrypoint /bin/bash -e CONTEXT=v1 -v $(PWD):/tmp -v /data:/data $(IMAGE)

parse_tomcat_access_logs.pl

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,45 @@
11
#!/usr/bin/perl
22

33
#we do it in perl, since that's available on ubuntu:latest
4-
# Results can be picked up by nl.vpro.monitoring.binder.ScriptMeterBinder
4+
5+
=head1 parse_tomcat_access_logs()
6+
7+
Make an abstract of the tomcat access logs
8+
9+
Two (optional) positional parameters
10+
11+
If three parameters:
12+
- directory
13+
- max age in minutes
14+
15+
If one parameter, directory defaults to /data/log
16+
- max age in minutes
17+
18+
=cut
519

620
use strict;
721
use warnings;
822

923

1024
my $dir="/data/logs";
11-
my $after = "1 week before now";
25+
my $age = "60"; # max age in minutes
1226
if (scalar(@ARGV) ge 2) {
1327
$dir = $ARGV[0];
14-
$after = $ARGV[1];
28+
$age = $ARGV[1];
1529
} elsif (scalar(@ARGV) ge 1) {
16-
$after = $ARGV[0];
30+
$age = $ARGV[0];
1731
}
1832

19-
my $findcommand="find $dir -name 'tomcat_access.log*'";
33+
my $after =`date --iso-8601=minutes --date="\${dataset_date} -$age minute"`;
34+
my $findcommand="find $dir -cmin -$age -name 'tomcat_access.log*'";
35+
my $context=$ENV{CONTEXT};
36+
if (! defined($context)) {
37+
$context="ROOT";
38+
}
39+
my $pathlength=$ENV{ACCESS_LOG_PATH_LENGTH};
40+
if (! defined($pathlength)) {
41+
$pathlength=2;
42+
}
2043
open(FILELIST,"$findcommand |")||die("can't open $findcommand |");
2144
my @filelist=<FILELIST>;
2245
close FILELIST;
@@ -43,6 +66,7 @@
4366
my $client=(split " ", $full_client)[0];
4467
my $request=$field[7];
4568
my $status=$field[8];
69+
$result{"status"}{"status=$status"}++;
4670
if ($status ge 300) {
4771
next;
4872
}
@@ -57,15 +81,20 @@
5781
my @split_full_path=split /\?/, $full_path;
5882
my $path=$split_full_path[0];
5983
my @split_path=split '/', $path;
60-
if (scalar(@split_path) < 4) {
84+
shift @split_path; # path starts with / so first element will be empty string, discard it.
85+
if ($split_path[0] eq $context) {
86+
shift @split_path;
87+
}
88+
if ($#split_path ge ($pathlength - 1)) {
89+
$#split_path = $pathlength - 1;
90+
}
91+
if (defined($split_path[0]) && $split_path[0] eq 'manage') {
6192
next;
6293
}
63-
my $api="$split_path[0]/$split_path[1]/$split_path[2]/$split_path[3]";
94+
my $short_path=join('/',@split_path);
6495

6596
$result{"clients"}{"client=$client"}++;
66-
$result{"methods"}{"method=$method,api=$api"}++;
67-
$result{"api"}{"api=$api"}++;
68-
$result{"status"}{"status=$status"}++;
97+
$result{"paths"}{"method=$method,path=$short_path"}++;
6998
}
7099
}
71100

@@ -75,3 +104,4 @@
75104
print ("tomcat_access_$name\t$count\t$key\n");
76105
}
77106
}
107+

0 commit comments

Comments
 (0)