Parse log file with groovy, extract time to detect slow and failed tests or processes

By neokrates, written on May 6, 2010

howto

  • Join date: 11-30-99
  • Posts: 224
View Counter:
  • 616 views
Rate it
Ad
Poll
  • You parse your logs using?

    View Results

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext

We have a server farm which runs 10000 etc builds. Many fail because of time out. To find the reason you should first find where the time was lost. Here is simple groovy script to do that.

Software:

✔ Groovy

Given: log/Why_So_Slow.log file has the format:

[HH:mm:ss] Log text 1
[HH:mm:ss] Log text 2
[HH:mm:ss] Log text 3
[HH:mm:ss] Log text 4

We just parse out the time and convert it to integer. Groovy regular express for such time Format is /\[(\d+:\d+:\d+)\]/.
Integer time = HH * 3600 + mm * 60 + ss

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
     def prevDt = 0
     def prevTime = 0 
           new File("log/Why_So_Slow.log" .eachLine{
      line->
             def m = line =~ /\[(\d+:\d+:\d+)\]/
      if(m.size()>0) {
       def time = m[0][1]
        def dtArr = time.split(":" 
      def dt = ( dtArr[0] as int )*3600 + ( dtArr[1] as int ) *60 + ( dtArr[2] as int )
             if((dt - prevDt)>30)
       println "$prevTime - $time :" + (dt - prevDt)/60
                    prevDt = dt
      prevTime = time 
            }
     }

💡 Remark: Most log files have similar time format. For the slight difference just change the regular expression accordingly.

Be Sociable, Share!
 
Does that help to solve your problem?
VN:F [1.8.5_1061]
Rating: 0 (from 0 votes)
0 votes 'YES'  0 votes 'NO'


TAGS

SOCIAL
Be Sociable, Share!

INCOMING SEARCH TERMS


Leave a Reply