Last active
October 15, 2015 13:19
-
-
Save jnankin/436bb0180619270903c0 to your computer and use it in GitHub Desktop.
Point this at a log of a chef run and it will find cookbooks taking longer than 60 seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$longRunningTime = 60; | |
$file = 'chef-run.log'; | |
$lastTime = null; | |
$lastLogStep = ''; | |
foreach(file($file) as $line){ | |
if (!preg_match('/^\\[(.*)\\](.*)$/U', $line, $matches)){ | |
continue; | |
} | |
else { | |
if ($lastTime && strtotime($matches[1]) - strtotime($lastTime) > $longRunningTime){ | |
echo "Long running line: $lastLogStep\n"; | |
echo "Last line occurred at: $lastTime \n"; | |
echo "This line occurred at: {$matches[1]}\n\n"; | |
} | |
$lastTime = $matches[1]; | |
$lastLogStep = $matches[2]; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment