Shop

Donnerstag, 29. März 2012

Groovy: Analyse Accesslogs

Analyse access logs with groovy. Compare a special behaviour on two different files.
 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!

Keine Kommentare:

Kommentar veröffentlichen