Parse log file with groovy, extract time to detect slow and failed tests or processesBy neokrates, written on May 6, 2010 |
howto |
- neokrates
- Email: uwarov@yahoo.com
- Website: http://www.thinkplexx.com
- Join date: 05-31-09
- Posts: 20
Rate it
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
Loading ...
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:
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.
|
LEARN MORE (amazon bookstore)
|
|
TAGS
|
|
RELATED
|
Pages
Posts
|
|
SOCIAL
|
|
INCOMING SEARCH TERMS
|


















