[root@cluster rolls]# chkconfig --list mon mon 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@cluster rolls]# chkconfig mon on
飯坂剛一
Version:4.3
Release: Nov 2007
Copyright 2007
SCSMONロールはノードの死活監視や、プロセスの状態監視、ログ監視、 ならびに異常を知見すると指定したアラートを発行する機能を NPACI Rocksのクラスタシステムに追加します。
フロントエンドノードだけにインストールされるツール: - mon
すべてのノードにインストールされるツール: - swatch
mon は多彩なモニタツールとアラート方法を提供する監視ツールです。
詳細なドキュメントと、設定例は /usr/share/doc/mon-1.2.0 に 格納れていますので参照してください。
このロールでは計算ノードの死活監視のための設定を意図して、 インストールされています。
ただ、アラートの通知先はデフォルトではroot@localとしているため、 実際の運用では外部へのメールアドレスを設定をする方が現実的です。
/etc/init.d/mon になりますが、デフォルトでは起動しないようになっています。 利用する場合は chkconfig コマンドでmonを有効にしてください。
[root@cluster rolls]# chkconfig --list mon mon 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@cluster rolls]# chkconfig mon on
設定ファイルは /etc/mon/mon.cf になりますが、 計算ノードのインストール時に自動生成されるため、 変更する場合は /etc/mon/mon.cf.local を修正してください。
Rocks はこのファイルを読み込んだ後に、 データベースに登録されているフロントエンドノードと 計算ノードのホスト名を追加します。
[root@cluster ~]# cat /etc/mon/mon.cf
### Extremely basic mon.cf file
### global options
cfbasedir = /etc/mon
pidfile = /var/run/mon.pid
statedir = /var/lib/mon/state.d
logdir = /var/lib/mon/log.d
dtlogfile = /var/lib/mon/log.d/downtime.log
alertdir = /usr/lib/mon/alert.d
mondir = /usr/lib/mon/mon.d
maxprocs = 20
histlength = 100
randstart = 60s
authtype = pam
userfile = /etc/mon/userfile
watch frontend
service ping
interval 5m
monitor ping.monitor
period wd {Mon-Fri} hr {7am-10pm}
alert mail.alert root@localhost
alertevery 1h
period wd {Sat-Sun}
service ssh
interval 10m
monitor telnet.monitor
period wd {Mon-Fri} hr {7am-10pm}
alertevery 1h
alertafter 2 30m
alert mail.alert root@localhost
service http
interval 60m
monitor http.monitor
allow_empty_group
period wd {Sun-Sat}
upalert mail.alert -S "web server is back up" mis
alertevery 45m
watch compute
service ping
interval 10m
monitor ping.monitor
period wd {Mon-Fri} hr {7am-10pm}
alert mail.alert root@localhost
alertevery 1h
period wd {Sat-Sun}
alert mail.alert root@localhost
/etc/mon/mon.cf.local 変更した場合は 次のように/etc/mon/mon.cf を修正してください。
[root@cluster ~]# dbreport mon > /etc/mon/mon.cf
モニタスクリプトが格納されているディレクトリは mon.cf で定義されている。
多くのスクリプトがあり、通常の運用ではこれを利用するだけでことが足りるはず。 自作する場合は、Failures の配列に文字列を与えることで、 アラートスクリプトが呼び出されるようになる。
[root@cluster mon]# ls -1 /usr/lib/mon/mon.d/*.monitor asyncreboot.monitor bootp.monitor cpqhealth.monitor dialin.monitor dir_file_age.monitor dns.monitor file_change.monitor flexlm.monitor foundry-chassis.monitor fping.monitor freespace.monitor ftp.monitor hpnp.monitor http.monitor https.monitor http_t.monitor http_tp.monitor http_tpp.monitor icecast.monitor imap.monitor informixdbspace.monitor informix.monitor ipsec.monitor ldap.monitor mailloop.monitor mon.monitor msql-mysql.monitor na_quota.monitor netappfree.monitor netsnmp-exec.monitor netsnmp-freespace.monitor netsnmp-proc.monitor nntp.monitor ntp.monitor ntservice.monitor phttp.monitor ping.monitor pop3.monitor postgresql.monitor printmib.monitor process-full-command-line.monitor process.monitor rd.monitor reboot.monitor remote.monitor rpc.monitor rptr.monitor samba.monitor seq.monitor silkworm.monitor smtp3.monitor smtp.monitor smtp_rt.monitor snmp_interface.monitor sqlconn.monitor ssh.monitor startremote.monitor tcpch.monitor tcp.monitor telnet.monitor traceroute.monitor umn_mon.monitor up_rtt.monitor xedia-ipsec-tunnel.monitor
アラートスクリプトが格納されているディレクトリは mon.cf で定義されている。
[root@cluster mon]# ls -1 /usr/lib/mon/alert.d/*.alert aim.alert bugzilla.alert file.alert gnats.alert hpov.alert irc.alert mail.alert netpage.alert qpage.alert sms.alert snapdelete.alert snpp.alert test.alert trap.alert winpopup.alert
モニタスクリプトと同様に、通常の運用ではこれを利用するだけでことが足りるはず。 自作する場合は、アラートスクリプトへmonから渡されるオプションについて 意識する必要がある。
| オプション | 説明 |
|---|---|
| -u | アラート種別、初回だけ偽値が渡される |
| -s | サービス名 |
| -g | ホストグループ名 |
| -h | ホスト名 |
| -t | 発生時間 |
| -l | 次回アラートまでの時間 |
daemontools のsvcを使ってhttpのデーモンを Keepaliveを行なう場合のアラートスクリプトの例
#!/usr/bin/perl
use strict;
use Getopt::Std;
getopts("s:g:h:t:l:u" . "D:S:");
# monが設定する共通オプション
my $summary = <STDIN>; chomp $summary;
my $alert = $Getopt::Std::opt_u ? "UPALERT" : "ALERT";
my $service = $Getopt::Std::opt_s;
my $hostgroup = $Getopt::Std::opt_g;
my $hostname = $Getopt::Std::opt_h;
my $timesec = $Getopt::Std::opt_t;
my $nextalertsec = $Getopt::Std::opt_l;
# このアラートスクリプトのオプション
my $dir = $Getopt::Std::opt_D;
my $signal = $Getopt::Std::opt_S;
my $progname = $1 if($0 =~ /([^\/]+)$/);
print "$progname: $hostgroup $hostname svc -$signal $dir\n";
exec "sudo", "svc", "-$signal", $dir
swatch は/var/log 以下のログファイルを走査して、 指定したパターンの文字列を見つけると、 登録しておいたアクションを実行するものです。
| オプション | 説明 |
|---|---|
| -c コンフィグファイル | 設定ファイルを指定。省略時は/root/.swatchrc。 |
| -f ファイル | 監視対象ファイルを指定。ファイルスキャンは1回のみ |
| -t ファイル | 監視対象ファイルを指定。ファイルスキャンを繰り返し行う。 |
システムログを監視する場合
# swatch -t /var/log/messages &
swatch の設定ファイルはデフォルトでは /root/.swatchrc になります。
この設定ファイルでは次のように記述します。
必ず watchfor よりも前で定義する必要があります。
ignore /パターン1/./パターン2/,....
watchfor /パターン1/
アクション1
アクション2
:
パターンの指定には正規表現が使用できます。
| 記述例 | 説明 |
|---|---|
| /error/i | 大文字と小文字を区別しない。 |
| /(error|warning)/ | errorもしくはwarningに合致したときにアクションを実行 |
| /[Ff]ailure/ | Failureとfailureに合致したときにアクションを実行 |
| /E.r/ | Eではじまりrで終わる3文字の文字列に合致したときにアクションを実行 |
| /E.*r/ | Eではじまりrで終わる文字列に合致したときにアクションを実行 |
アクションを複数指定する場合は、行を分けて記述します。
| アクション | 説明 |
|---|---|
| echo[=mode] | ターミナル上にメッセージを表示。modeにはnormal、bold、blink、underscore、inverseを指定可能。 |
| bell[=N] | N回ビープ音を鳴らす。指定しなければ1回。 |
| exec=command | 指定されたコマンドを実行。 |
| ignore | 何もしない。 |
| mail[=address:address…] [,subject="text"] | 指定されたアドレス(複数可能)にメッセージメールを送信。アドレス省略時はswatchを実行したユーザへ送信。 |
| pipe=command | コマンドにパイプとして処理結果を渡す。 |
| write[=user:user:…] | writeコマンドを利用してメッセージをコンソール上に表示。 |
/etc/init.d/swatch になりますが、デフォルトでは起動しないようになっています。 利用する場合は chkconfig コマンドでswatchを有効にしてください。
[root@cluster rolls]# chkconfig --list swatch swatch 0:off 1:off 2:off 3:off 4:off 5:off 6:off [root@cluster rolls]# chkconfig mon swatch
#!/bin/bash
#
# swatch
#
# chkconfig: 2345 90 35
# description: swatch start/stop script
# Source function library.
. /etc/rc.d/init.d/functions
PATH=/sbin:/usr/local/bin:/bin:/usr/bin
mkdir -p /var/log/swatch
start() {
# Start daemons.
ls /var/run/swatch_*.pid > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo -n "Starting swatch"
pno=0
for conf in /etc/swatch/*.conf
do
pno=`expr $pno + 1`
WATCHLOG=`grep "^# logfile" $conf | awk '{ print $3 }'`
swatch --config-file $conf --tail-file $WATCHLOG \
--script-dir=/tmp --awk-field-syntax --use-cpan-file-tail --daemon \
--pid-file /var/run/swatch_$pno.pid \
>> /var/log/swatch/swatch.log 2>&1
RETVAL=$?
[ $RETVAL != 0 ] && return $RETVAL
done
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/swatch
return $RETVAL
else
echo "swatch is already started"
fi
}
stop() {
# Stop daemons.
ls /var/run/swatch_*.pid > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -n "Shutting down swatch"
for pid in /var/run/swatch_*.pid
do
kill $(cat $pid)
rm -f $pid
done
echo
rm -f /var/lock/subsys/swatch /tmp/.swatch_script.*
else
echo "swatch is not running"
fi
}
status() {
ls /var/run/swatch_*.pid > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo -n "swatch (pid"
for pid in /var/run/swatch_*.pid
do
echo -n " `cat $pid`"
done
echo ") is running..."
else
echo "swatch is stoped"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo "Usage: swatch {start|stop|restart|status}"
exit 1
esac
exit $RETVAL