check_pgsql
PosrgreSQL DBに対する接続をチェックするプラグイン。
以下
DB名 | checkDB |
---|---|
DBユーザー | nagios |
パスワード | abcd |
と仮定。
対象
ローカル or リモート
アーカイブ内での位置
plugins/check_pgsql
必要なもの
- postgresql
など。
コンパイル時に下記オプションを指定する必要がある。--with-pgsql=/usr/local/pgsql
準備
チェック用のDBを作る。
/usr/local/pgsql/bin/createuser -A -d nagios /usr/local/pgsql/bin/createdb -U nagios checkDB /usr/local/pgsql/bin/psql checkDB
ALTER USER nagios WITH PASSWORD 'abcd'
実行
DBに2秒で接続できないと WARNING、8秒で接続できないと CRITICAL。
/usr/local/nagios/libexec/check_pgsql -H 192.168.0.2 -d checkDB -l nagios -p 'abcd' -w 2 -c 8
DBの利用形態によってチェックの方法が変わる
- ネットワーク越しでDBを利用していない
→NRPE経由でチェックする。下記コマンドはhostAのnrpe.cfgに記述。Nagios hostA check_nrpe → NRPE check_pgsql PosrgreSQL DB - ネットワーク越しでDBを利用している
- 監視サーバーからの利用である
→直接チェックする。下記コマンドはnagios本体のcheckcommands.cfgに記述。Nagios hostA check_pgsql → PosrgreSQL DB - 監視サーバーからの利用でない(hostAからhostBへの利用である)
→NRPE経由でチェックする。下記コマンドはhostAのnrpe.cfgに記述。Nagios hostA hostB check_nrpe → NRPE check_pgsql → PosrgreSQL DB
- 監視サーバーからの利用である
ネットワーク越しでDBを利用していない
監視対象ホスト(DB接続先)のnrpe.cfgでの定義
command[check_pgsql]=/usr/local/nagios/libexec/check_pgsql -d checkDB -l nagios -p $ARG1$ -w $ARG2$ -c $ARG3$
サービスの定義
define service{ use generic-service host_name hostA service_description PostgreSQL is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 5 retry_check_interval 1 notification_interval 240 notification_period 24x7 notification_options c,r check_command check_nrpe!'abcd'!2!8 contact_groups linux-admins }
ネットワーク越しでDBを利用している 監視サーバーからの利用である
checkcommands.cfgでの定義
vi /usr/local/nagios/etc/checkcommands.cfg
# 'check_pgsql' command definition define command{ command_name check_pgsql command_line $USER1$/check_pgsql -H $HOSTADDRESS$ -d checkDB -l nagios -p $ARG1$ -w $ARG2$ -c $ARG3$ }
サービスの定義
define service{ use generic-service host_name hostA service_description PostgreSQL is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 5 retry_check_interval 1 notification_interval 240 notification_period 24x7 notification_options c,r check_command check_pgsql!'abcd'!2!8 contact_groups linux-admins }
ネットワーク越しでDBを利用している 監視サーバーからの利用でない
監視対象ホスト(DB接続元)のnrpe.cfgでの定義
command[check_pgsql]=/usr/local/nagios/libexec/check_pgsql -H $ARG1$ -d checkDB -l nagios -p $ARG2$ -w $ARG3$ -c $ARG4$
サービスの定義
define service{ use generic-service host_name hostA service_description PostgreSQL is_volatile 0 check_period 24x7 max_check_attempts 3 normal_check_interval 5 retry_check_interval 1 notification_interval 240 notification_period 24x7 notification_options c,r check_command check_nrpe!192.168.0.2!'abcd'!2!8 contact_groups linux-admins }