NRPEによるディスク容量の自動監視 Windows & Linux

今までディスク容量のチェックは、Cactiでの目視確認で行っていましたが、
急激な容量増加による障害が発生したため、10分間隔の自動監視設定を行いました。


初め各サーバにお手製スクリプトを置いて、Cronで回す方法を考えましたが、
Windowsサーバも同じように監視することを考え、NagiosのアドオンであるNRPEデーモンに統一することに決めました。

NRPE概要

監視サーバのNagiosからcheck_nrpeプラグイン経由で監視対象サーバのNRPEデーモンに問い合わせを行い、
NRPEデーモンは、別途用意されているNRPEプラグインを呼び出してリソース状況を取得し返します。

[check_nrpeプラグイン]<=>[Nagiosプロセス] ※監視サーバ
↑↓
[NRPEデーモン]<=>[プラグイン]<=>[リソース] ※監視対象サーバ

※監視対象がWindowsの場合も仕組みは変わらず、Windows用の(nrpe_nt)(nrpe_nt plugins)が用意されています。

監視サーバ Nagios側の設定

既にNagiosが設定されていることを前提にNRPE部分だけになります。

NRPEの入手先
  1. http://www.nagios.org/download/download.php
  2. Step 3: Get Addons → [GO]
  3. ライセンス許諾ページ
  4. NRPE2.1.2 → [GO]
NRPEのmake
# cd /usr/local/src/
# tar xvfz tar xvfz nrpe-2.12.tar.gz
# cd nrpe-2.12
# ./configure --enable-command-args
※オプション --enable-command-argsは、監視閾値をNagios側で設定できるようにする。
*
*
*** Configuration summary for nrpe 2.12 03-10-2008 ***:

 General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the NRPE daemon and client.
# make all
*** Compile finished ***

If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.

Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.
# cp src/check_nrpe /usr/local/nagios/libexec/
※[check_nrpeプラグイン]をnagiosが使用できるようにコピーしておく。
Nagiosの設定ファイル編集

※監視対象サーバで、nrpe.cfgを編集した後に行う。

/usr/local/nagios/etc/objects/commands.cfgを編集追記

# check nrpe
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

/usr/local/nagios/etc/objects/services.cfgを編集追記

define service {
        host_name               adsrv.hq.ad.gala.jp
        service_description     Disk check C:
        check_command           check_nrpe!check_disk_C
        contact_groups          admins
        use                     generic-service
}

check_nrpe!check_disk_Cの「check_disk_C」の部分はnrpe.cfgで編集したコマンド名に合わせる

# /etc/init.d/nagios restart

設定反映後、しばらくウェブ画面なりで状況を見守る。

Windows監視対象サーバ側の設定

※動作確認済OS

配置とインストール

2個のフォルダを対象WindowsのC:直下に置く
「nrpe_nt.0.8b-bin」を「nrpe_nt」にリネーム

コマンドプロンプト起動

# cd C:\nrpe_nt\bin
# NRPE_NT -i
NRPE_NT Service sucessfully installed!
NRPEデーモン設定ファイルnrpe.cfgの編集

ここで監視サーバのIPアドレスと監視したいリソースのコマンドを作成します。

・C:\nrpe_nt\binの中のnrpe.cfgをエディタで編集する

allowed_hosts=[監視サーバIPアドレス]
※上記編集
command[check_disk_C]=C:\nrpe_nt plugins\bin\diskspace_nrpe_nt.exe C: 85 90
※最下行追記
※コマンド名(check_disk_C)チェックしたいパーティション(C:)使用容量警告%(85)使用容量クリティカル%(90)
NRPEサービス起動
  1. Windowsの[サービス]を起動
  2. [Nagios Remote Plugin Executor for NT/W2K]を開始

※nrpe.cfgを修正した場合は、都度サービスの再起動が必要。


Linux監視対象サーバ側の設定

※監視サーバでmake済みのnrpe-2.12を各監視対象サーバへコピーしておく

Nagiosユーザ追加

# useradd -d /usr/local/nagios nagios
# passwd nagios

ディレクトリ作成

# mkdir -p /usr/local/nagios/etc
# mkdir -p /usr/local/nagios/bin
# mkdir -p /usr/local/nagios/libexec

・NRPE監視デーモンコピー

# cp /uar/local/src/nrpe-2.12/src/nrpe /usr/local/nagios/bin/

・NRPE設定ファイルコピー

# cp /uar/local/src/nrpe-2.12/sample-config/nrpe.cfg /usr/local/nagios/etc/

Nagiosプラグインをコピー
※監視サーバの/usr/local/nagios/libexec/から各監視対象サーバへコピーしておく

# cp /tmp/libexec/* /usr/local/nagios/libexec/

・NRPE起動スクリプトコピー(Redhat/CentOS) debian/suse別途ファイルあり

# cp /uar/local/src/nrpe-2.12/init-script /etc/rc.d/init.d/nrpe
# chmod 755 /etc/init.d/nrpe

・サーバ起動時設定※CentOSの場合

# cd /etc/rc.d/rc3.d
# ln -s ../init.d/nrpe  S90nrpe
# ln -s ../init.d/nrpe  K90nrpe


ディレクトリオーナー設定

# chown nagios /usr/local/nagios/* -R
NRPEデーモン設定ファイルnrpe.cfgの編集

Windowsの場合と基本同じです。
ここで監視サーバのIPアドレスと監視したいリソースのコマンドを作成します。

・/usr/local/nagios/etc/nrpe.cfgを編集

allowed_hosts=[監視サーバIPアドレス]
※上記編集
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% -p /dev/hda1
※最下行追記
※コマンド名(check_hda1)チェックしたいパーティション(/dev/hda1)残り容量警告%(15)残り容量クリティカル%(10)
※Windowsの場合と違い、使用容量%ではなく、残り容量%であることに注意。

補足

※NRPEのプラグインでは他にも、CPU/メモリ/ロードアベレージ/プロセス状態/メールキューなど色々設定できます。
※参考にした本

Nagios 2.0オープンソースではじめるシステム&ネットワーク監視

Nagios 2.0オープンソースではじめるシステム&ネットワーク監視

今回はまった箇所

WindowsのNRPTデーモンnrpe_nt.0.7f-binでは、Windows server 2003にて次のエラーが起き値の取得に失敗しました。
http://www.nagiosexchange.org/cgi-bin/page.cgi?g=2153.html;d=1

NRPE_NT:  Error: Exception in handle_connection-packet_Send: -1073741819

そのため、nrpe_nt.0.8b-bin.zipを使用しています。