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

By neokrates, written on May 6, 2010

howto

Rate it
  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...
Ad
Poll
  • You parse your logs using?

    • Something else (100%, 5 Votes)
    • Grep (any version) (0%, 0 Votes)
    • Shell script you wrote (0%, 0 Votes)
    • Log parsing tool (0%, 0 Votes)
    • Program you wrote (0%, 0 Votes)
    • Any text editor (0%, 0 Votes)

    Total Voters: 5

    Vote

    Loading ... Loading ...
Feeds:
  • bodytext bodytext bodytext
Most popular search terms:

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:

[v] 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 
            }
     }


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

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

LEARN MORE (amazon bookstore)

TAGS

RELATED
Pages
Posts

SOCIAL
Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • BlinkList
  • Blogosphere News
  • E-mail this story to a friend!
  • Furl
  • LinkArena
  • Live
  • MisterWong
  • Print this article!
  • StumbleUpon
  • Technorati
  • Webnews.de
  • YahooMyWeb

INCOMING SEARCH TERMS


Leave a Reply