Previously, I wrote about how puppet v2 had memory leaks so I had to have Nagios restart puppet. (http://legendofgou.blogspot.com/2013/10/puppet-has-memory-leaks.html)
Well, I finally upgraded to puppet v3 a few months ago and the same plugin doesn't seem to work anymore. Below is the updated Nagios plugin to restart the puppet agent. I'm not saying v3 has memory problems but why not have it monitor and restart dead agents or agents that may be having issues?
#!/usr/bin/perl
# Author: Gou Yang
# Purpose: Checks and restarts puppet if the memory is too high
# or if puppet is dead
use strict;
my $default;
my $pcount;
my @Results;
my $memResults;
my $logResults;
#puppet seems to hang randomly
#so, if puppet hasn't logged to messages then it should be restarted
$logResults=`sudo /usr/bin/tail -400 /var/log/messages | grep puppet-agent | grep Finished | wc -l`;
if ($logResults < 1) {
`sudo /etc/init.d/puppet restart`;
print "WARNING - puppet-agent isn't reporting, restarting puppet";
exit 1;
}
$default=10;
chomp($pcount=`ps aux | grep "/usr/bin/ruby /usr/bin/puppet agent" | grep -v grep | wc -l`);
if ($pcount < 2) {
if ($pcount < 1) {
print "WARNING - No Puppet Process found, restarting puppet";
`sudo /etc/init.d/puppet restart`;
exit 1;
}
@Results=split(" ",`ps aux | grep "/usr/bin/ruby /usr/bin/puppet agent" | grep -v grep`);
$memResults=$Results[3];
if ($memResults > $default) {
`sudo /etc/init.d/puppet restart`;
print "WARNING - Memory utilization of $memResults\% is too high, restarting puppet";
exit 1;
}
else{
print "OK - Memory utilization is $memResults\%";
exit 0;
}
}
else{
print "WARNING - Found $pcount puppet processes";
exit 1;
}