VMware ESXiをNagiosから監視するPluginとその設定

ESXiユーザ作成

まずは、ESXi側に監視用のユーザを作成します。今回はnagiosユーザという読み取り専用のユーザを作成しました。

vSpereクライアントのユーザタブよりユーザを作成します。    

 

作成したユーザはnagiosです。    

権限タブより権限を割り当てます。読み取り専用権限を付与しています。  

nagiosユーザに読み取り専用権限が付与されました。  

ESXi監視用plugin導入

pluginのダウンロードと配置

今回は以下のURLから取得したpluginを使います。

exchange.nagios.org

Nagiosサーバーのpluginsディレクトリに配置します。

# cp check_esx3-0.5.pl /usr/lib64/nagios/plugins/check_esx.pl
# chmod 755 /usr/lib64/nagios/plugins/check_esx.pl

前提RPMインストール

必要に応じて前提となるRPMパッケージをインストールします。

# yum -y install epel-release
# yum -y install perl-Nagios-Plugin

vSphere Perl SDKインストール

ESXiの情報を取得するために、vSphereのPerl SDKを導入します。

まずはダウンロードします。

vSphere Perl SDK for vSphere 6.0 - VMware Developer Center

タウンロードしたtarファイルを解凍して、インストールスクリプトを実行します。インストール先のディレクトリなどが聞かれるので、必要に応じて変更しながらウィザードを進めます。

# tar -xvf VMware-vSphere-Perl-SDK-6.0.0-3561779.x86_64.tar.gz
# cd vmware-vsphere-cli-distrib/
# ./vmware-install.pl -d

インストールの際にOpensslのバージョンが足りてないと、以下のようなエラーが出てインストールできないので、必要ならインストールまたはアップデートします。

Openssl-devel is not installed on the system.
openssl-devel 0.9.7 is required for encrypted connections.
Please install openssl-devel version 0.9.7 or greater.

動作確認

ここまで設定するとpluginが動くはずです。引数無しで打つと以下のようにヘルプが表示されます。

# /usr/lib64/nagios/plugins/check_esx.pl 
Usage: check_esx.pl -D <data_center> | -H <host_name> [ -N <vm_name> ]
    -u <user> -p <pass> | -f <authfile>
    -l <command> [ -s <subcommand> ]
    [ -x <black_list> ] [ -o <additional_options> ]
    [ -t <timeout> ] [ -w <warn_range> ] [ -c <crit_range> ]
    [ -V ] [ -h ]

実際にESXiのCPUの使用率を取ってみます。正常に取得できているのがわかります。このコマンドをNagios側に設定していきます。

# /usr/lib64/nagios/plugins/check_esx.pl -H (esxi_host) -u nagios -p P@ssw0rd-l cpu -s usage -w 80 -c 90 -t 60
CHECK_ESX.PL OK - cpu usage=1.13 % | cpu_usage=1.13%;80;90

Nagiosへの設定例

先ほどのコマンドをNagiosに設定してきます。

引数で必要なユーザとパスワードはresourceに設定しておきます。

/etc/nagios/private/resource.cfg

# Sets $USER1$ to be the path to the plugins
$USER1$=/usr/lib64/nagios/plugins

# Store nagios user and password
$USER2$=nagios
$USER3$=P@ssw0rd

コマンド設定して、

define command{
        command_name    check_esxi_with_threshold
        command_line    /usr/bin/perl $USER1$/check_esx.pl -H $HOSTADDRESS$ -u $USER2$ -p $USER3$ -l $ARG1$ -s $ARG2$ -w $ARG3$ -c $ARG4$
        }
define command{
        command_name    check_esxi
        command_line    /usr/bin/perl $USER1$/check_esx.pl -H $HOSTADDRESS$ -u $USER2$ -p $USER3$ -l $ARG1$ -s $ARG2$
        }

このように設定してみました。

define host{
        use             linux-server
        host_name       my-esxi
        host_groups     esxi
        address         172.16.128.128
        }

define hostgroup{
        hostgroup_name  esxi
        alias           esxi
        }

define service{
        use                             local-service
        hostgroup_name                  esxi
        service_description             ESXi Host CPU
        check_command                   check_esxi_with_threshold!cpu!usage!80!90
        notifications_enabled           0
        }
define service{
        use                             local-service
        hostgroup_name                  esxi
        service_description             ESXi Host NICs status
        check_command                   check_esxi!net!nic
        notifications_enabled           0
        }
define service{
        use                             local-service
        hostgroup_name                  esxi
        service_description             ESXi Host Memory Usage
        check_command                   check_esxi_with_threshold!mem!usage!80!90
        notifications_enabled           0
        }
define service{
        use                             local-service
        hostgroup_name                  esxi
        service_description             ESXi Host Runtime Health
        check_command                   check_esxi!runtime!health
        notifications_enabled           0
        }

上記の設定をして、実際に動いているNagiosの監視画面です。

オプション纏め

最後にこの方法で取得できる情報をコマンドラインのオプションと一緒にまとめておきます。

  • CPU関連
Option Description
-l cpu all cpu info
-l cpu -s usage CPU usage in percentage
-l cpu -s usagemhz CPU usage in MHz

-Memory関連

Option Description
-l mem all mem info
-l mem -s usage mem usage in percentage
-l mem -s usagemb mem usage in MB
-l mem -s swap swap mem usage in MB
-l mem -s overhead additional mem used by VM Server in MB
-l mem -s overall overall mem used by VM Server in MB
  • Network関連
Option Description
-l net all net info
-l net -s usage overall network usage in KBps(Kilobytes per Second)
-l net -s receive receive in KBps(Kilobytes per Second)
-l net -s send send in KBps(Kilobytes per Second)
-l net -s nic makes sure all active NICs are plugged in
  • I/O関連
Option Description
-l io all disk io info
-l io -s read read latency in ms
-l io -s write write latency in ms
-l io -s aborted aborted commands count
-l io -s resets bus resets count
-l io -s kernel kernel latency in ms
-l io -s device device latency in ms
-l io -s queue queue latency in ms
  • Runtime関連
Option Description
-l runtime all runtime info
-l runtime -s status overall host status (gray/green/red/yellow)
-l runtime -s issues all issues for the host
-l runtime -s con connection state
-l runtime -s health checks cpu/storage/memory/sensor status
-l runtime -s maintenance shows whether host is in maintenance mode
-l runtime -s list(vm) list of VMWare machines and their statuses
  • VMFS関連
Option Description
-l vmfs all datastore info
-l vmfs -s (データストア名) info for datastore with name (name)
  • Service関連
Option Description
-l service shows all services
-l service -s (サービス名) check the state of one or several services specified by (names), syntax for (names)

さいごに

様々な情報が取れる多機能なPluginです。エージェントレスなのも嬉しいですね。