プレイヤーズ・ハイ

 雑多な日記

Nagios に自作プラグイン (Tokyo Tyrant 稼働確認) を追加

とあるサービスで Key-Value Store として Tokyo Tyrant を使っています。

Tokyo Tyrant くん、パフォーマンスは素晴らしいのですが、過去に一度、プロセスは上がっているのに読み書きができなくなったことがあるらしく、Nagios 自作プラグインで稼働監視を行うことにしました。

仕組みは簡単で、一定間隔で、監視用のキーに一意の値を書いて読むだけです。

ちなみに tcrmgr コマンドにはタイムアウトを指定するオプションがないのですが、そこは Nagios さんによしなにやっていただくことになっています。

監視用シェルスクリプト

  • monitoring_ttserver.sh
#!/bin/sh

#
# ----------------------------------------------------------------------
# Variables
# ----------------------------------------------------------------------
#

#
# Exit Code
#

OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3


#
# Key & Value
#

KEY=monitoring
VALUE=`date '+%Y%m%d%H%M%S'`


#
# ----------------------------------------------------------------------
# write test data & read test data
# ----------------------------------------------------------------------
#

# write test data
/usr/local/bin/tcrmgr put -port 4000 localhost ${KEY} ${VALUE}
if [ "${?}" = 0 ]
then
    STATUS=write_OK
    # read test data
    /usr/local/bin/tcrmgr get -port 4000 localhost ${KEY}
    if [ "${?}" = 0 ]
    then
        STATUS=write_OK_and_read_OK
    else
        STATUS=write_OK_but_read_NG
    fi
else
    STATUS=write_NG
fi


#
# ----------------------------------------------------------------------
# return status code
# ----------------------------------------------------------------------
#

case $STATUS in
    write_OK)  echo "** write data to Tokyo Tyrant is OK, but read data to Tokyo Tyrant is UNKNOWN. **"
        exit $WARNING ;;
    write_OK_and_read_OK)  echo "** write data to Tokyo Tyrant is OK, and read data to Tokyo Tyrant is OK. **"
        exit $OK ;;
    write_OK_but_read_NG)  echo "** write data to Tokyo Tyrant is OK, but read data to Tokyo Tyrant is NG. **"
        exit $CRITICAL ;;
    write_NG)  echo "** write data to Tokyo Tyrant is NG. **"
        exit $CRITICAL ;;
    *)  echo "State of Tokyo Tyrant is UNKNOWN."
        exit $UNKNOWN ;;
esac

echo "** Timeout, or some errors may occured. **"
exit $UNKNOWN

作成したシェルスクリプトを Nagios に登録

$ cat /etc/nagios/conf.d/commands.cfg    

define command {
    command_name    check_ttserver_function
    command_line    /usr/lib64/nagios/plugins/monitoring_ttserver.sh
}

サービス登録

$ cat /etc/nagios/nagios.cfg

## tt function
define service {
  use                  generic-service
  host                 hostname
  service_description  ttserver function
  check_command        check_ttserver_function
}

Nagios 設定再読み込み

# 設定ファイルのシンタックスチェック
$ sudo nagios -v /etc/nagios/nagios.cfg
# 問題なければ再読み込み
$ sudo service nagios reload