wiki:tech/SystemMonitor

監視メモ

特定のログが出るまで監視

特定のエラーメッセージが出たら何か処理をしたい場合、tailとgrep(egrep)を利用すると、メッセージを追跡することができます。

例えば、/var/log/messagesに下記のようなログが出力されapache2が死んだ場合、

Out of memory: kill process 18740 (apache2) score 46907 or a child

次のようなスクリプトでapache2の死亡を監視し、死亡を検出したらapache2を再起動することができます。

#!/bin/sh
tail -F /var/log/messages  | egrep -qF "Out of memory: kill process [0-9]+ (apache2)"
service apache2 restart