uptimeを呼んで数値を得るのではなくて直接/procから数値を読むようにした。
同時にswapの空きが10Mを切ったときも、リスタートするように変更。
元の書き殴りじゃあんまりなのでちゃんとstrictとwarningsを指定した。しばらく使いそうだしね。
#!/usr/bin/perl use strict; use warnings; my $limit15 = 10; my $limit5 = 15; my $limit1 = 30; my $limitM = 10 * 1024; print "$limitM:$limit15:$limit5:$limit1\n"; while(1){ my $swapFree = 0; my $load15 = 0; my $load5 = 0; my $load1 = 0; open MEMINFO,"/proc/meminfo" or die; while(<MEMINFO>){ next unless /^SwapFree/; my @workTbl = split(/[\s:]+/); $swapFree = $workTbl[1]+0; } close MEMINFO; open UPTIME,"/proc/loadavg" or die; while(<UPTIME>){ my @workTbl = split(/[\s,]+/); $load15 = $workTbl[2] + 0; $load5 = $workTbl[1] + 0; $load1 = $workTbl[0] + 0; } close UPTIME; my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime(time()); $mon += 1; $year += 1900; if($load15 > $limit15){ if($load5 > $limit5){ if($load1 > $limit1){ print '('. join(':',($swapFree,$load1,$load5,$load15)).") restart at $year/$mon/$mday $hour:$min:$sec : cpu busy\n" ; system("/sbin/service httpd restart"); sleep(60); } else { print ' ('. join(':',($swapFree,$load1,$load5,$load15)).") step2 at $year/$mon/$mday $hour:$min:$sec \n" ; } } else { print ' ('. join(':',($swapFree,$load1,$load5,$load15)).") step1 at $year/$mon/$mday $hour:$min:$sec \n" ; } } if($swapFree <= $limitM){ print '('. join(':',($swapFree,$load1,$load5,$load15)).") restart at $year/$mon/$mday $hour:$min:$sec : memlow \n" ; system("/sbin/service httpd restart"); sleep(30); } sleep(10); }