Groovy: Analyse Accesslogs

Analyse access logs with groovy. Compare a special behaviour on two different files.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pattern = ~/.*\\/(.*\.jsp).*/  
data = new HashMap()
calculate("c:/P7_ARCTIS_access_log.2012_01_31%2336[1]", 0);
calculate("c:/P7_ARCTIS_access_log.2012_03_23%2336[1]", 1);
def calculate(filename, i) {
def file = new File(filename);
file.eachLine{line ->
if(line.contains(".jsp")) {
m = line=~pattern
def jsp = m[0][1]
if(!data.containsKey(jsp)) {
data.put(jsp, [0,0]);
}
int[] werte = data.get(jsp);
werte[i] = werte[i]+1;
data.put(jsp, werte);
}
}
}
println data

Here we are!