Skip to content

Instantly share code, notes, and snippets.

@jnankin
Last active October 15, 2015 13:19
Show Gist options
  • Save jnankin/436bb0180619270903c0 to your computer and use it in GitHub Desktop.
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
<?
$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