今日はNagiosのパフォーマンス情報をグラフ化するツール、
PerfParseについて、備忘録的なメモです。
Nagiosは既に「/usr/local/nagios」以下へインストールされている前提とします。
事前準備
「gd」「glibc」を予めインストールしておきます。
また、パフォーマンスデータの格納にデータベースが必要です。
今回データベースはMySQLを利用します。「mysql-devel」も忘れずに。
PHPも使いますので、予めインストールしておきます。
ソケットファイルの指定
「/etc/my.cnf」「/etc/php.ini」でMySQLが使用するソケットファイルのパスを揃えます。
# vi /etc/my.cnf [mysqld] socket=/tmp/mysql.sock [client] socket=/tmp/mysql.sock # vi /etc/php.ini mysql.default_socket =/tmp/mysql.sock
データベースのセットアップ
MySQLをセットアップします。perfparseユーザーとperfparseデータベースを作成し、
parfparseユーザーへ権限を付与します。
# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.52 Source distribution Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> CREATE DATABASE perfparse; Query OK, 1 row affected (0.00 sec) mysql> GRANT ALL ON perfparse.* TO perfparse@localhost IDENTIFIED BY 'perfparse'; Query OK, 0 rows affected (0.00 sec) mysql> FLUSH PRIVILEGES; mysql> exit
PerfParseのインストール
PerfParseをインストールします。
# cd /usr/local/src # wget http://sourceforge.net/projects/perfparse/files/perfparse/perfparse-0.106.1/perfparse-0.106.1.tar.gz/download # tar -xvzf perfparse-0.106.1.tar.gz # cd perfparse-0.106.1 # ./configure --prefix=/usr/local/nagios --with-imagedir=/usr/local/nagios/share/images/ --with-cgidir=/usr/local/nagios/sbin --with-http_image_path=/nagios/images --with-phpuidir=/usr/local/nagios/share # make # make install # chmod 777 /usr/local/nagios/share/templates_c
perfparseデータベース環境を作成します。
# cd /usr/local/src/perfparse-0.106.1/scripts/ # cat mysql_create.sql | mysql -u perfparse -p -D perfparse
設定ファイルの設定を行います。
「perfparse.cfg」をコピーし、「Service_Log」を修正します。
# cd /usr/local/nagios/etc/ # cp -p perfparse.cfg.example perfparse.cfg # vi perfparse.cfg #Service_Log = "|/var/log/nagios/perfparse/perfdata-service.log" Service_Log = "-"
「process-host-perfdata」および「process-service-perfdata」コマンドをPerfParse用に修正します。
# vi /usr/local/nagios/etc/objects/commands.cfg # 'process-host-perfdata' command definition define command{ command_name process-host-perfdata command_line /usr/bin/printf "%b" "$TIMET$\t$HOSTNAME$\t$HOSTDESC$\t$HOSTOUTPUT$\t$HOSTSTATE$\t$HOSTPERFDATA$\n" | /usr/local/nagios/bin/perfparse-log2mysql -c /usr/local/nagios/etc/perfparse.cfg } # 'process-service-perfdata' command definition define command{ command_name process-service-perfdata command_line /usr/bin/printf "%b" "$TIMET$\t$HOSTNAME$\t$SERVICEDESC$\t$SERVICEOUTPUT$\t$SERVICESTATE$\t$SERVICEPERFDATA$\n" | /usr/local/nagios/bin/perfparse-log2mysql -c /usr/local/nagios/etc/perfparse.cfg }
後はNagiosを再起動します。
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 3.3.1 Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 07-25-2011 License: GPL Website: http://www.nagios.org Reading configuration data... Read main config file okay... Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'... Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'... Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'... Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'... Processing object config directory '/usr/local/nagios/etc/_test_environment'... Processing object config file '/usr/local/nagios/etc/_test_environment/hosts.cfg'... Processing object config file '/usr/local/nagios/etc/_test_environment/services.cfg'... Read object config files okay... Running pre-flight check on configuration data... Checking services... Checked 42 services. Checking hosts... Checked 3 hosts. Checking host groups... Checked 1 host groups. Checking service groups... Checked 0 service groups. Checking contacts... Checked 1 contacts. Checking contact groups... Checked 1 contact groups. Checking service escalations... Checked 0 service escalations. Checking service dependencies... Checked 0 service dependencies. Checking host escalations... Checked 0 host escalations. Checking host dependencies... Checked 0 host dependencies. Checking commands... Checked 27 commands. Checking time periods... Checked 5 time periods. Checking for circular paths between hosts... Checking for circular host and service dependencies... Checking global event handlers... Checking obsessive compulsive processor commands... Checking misc settings... Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check # /etc/init.d/nagios restart Running configuration check...done. Stopping nagios: done. Starting nagios:This account is currently not available. done.
設定に問題なければ、データベースにデータが蓄積されます。
]# mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 180 Server version: 5.1.61 Source distribution Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use perfparse; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> select * from perfdata_service_bin; +-----+-----------+---------------------+---------+---------------------+----------+------+----------+-------+ | id | host_name | service_description | metric | ctime | value | warn | critical | state | +-----+-----------+---------------------+---------+---------------------+----------+------+----------+-------+ | 1 | web2 | LOADAVERAGE | load1 | 2012-05-05 11:50:22 | 0 | 5 | 10 | 0 | | 2 | web2 | LOADAVERAGE | load5 | 2012-05-05 11:50:22 | 0 | 5 | 10 | 0 | | 3 | web2 | LOADAVERAGE | load15 | 2012-05-05 11:50:22 | 0 | 5 | 10 | 0 | | 4 | localhost | HTTP | time | 2012-05-05 11:50:42 | 0.062616 | NULL | NULL | 0 |
画面はこんな感じです。
TIPS:不要データの消し方
監視設定を変えた場合、PerfParseからデータを消したい場合があります。
- ホストの場合は「perfdata_host」
- サービスの場合は「perfdata_service」
- 実データの場合は「perfdata_service_bin」
のデータに対して「is_deleted」のカラムに"1"を設定し、「perfparse-db-purge」コマンドを実行します。
mysql> DESC perfdata_host; +------------------------+-------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-------------------------+------+-----+---------+-------+ | host_id | int(11) | NO | UNI | NULL | | | host_name | varchar(75) | NO | PRI | NULL | | | group_name | varchar(75) | YES | MUL | NULL | | | raw_delete_policy | int(11) | YES | | NULL | | | raw_delete_policy_name | varchar(20) | YES | MUL | NULL | | | raw_delete_policy_type | enum('user','template') | NO | | NULL | | | bin_delete_policy | int(11) | YES | | NULL | | | bin_delete_policy_name | varchar(20) | YES | MUL | NULL | | | bin_delete_policy_type | enum('user','template') | NO | | NULL | | | is_deleted | tinyint(4) | YES | | 0 | | +------------------------+-------------------------+------+-----+---------+-------+ 10 rows in set (0.00 sec) mysql> DESC perfdata_service; +------------------------+--------------------------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +------------------------+--------------------------------+------+-----+---------+-------+ | service_id | int(11) | NO | UNI | NULL | | | host_name | varchar(75) | NO | PRI | NULL | | | service_description | varchar(75) | NO | PRI | NULL | | | last_perfdata_raw | int(11) | YES | UNI | NULL | | | raw_delete_policy | int(11) | YES | | NULL | | | raw_delete_policy_name | varchar(20) | YES | MUL | NULL | | | raw_delete_policy_type | enum('template','user','host') | NO | | NULL | | | is_deleted | tinyint(4) | YES | | 0 | | +------------------------+--------------------------------+------+-----+---------+-------+ 8 rows in set (0.00 sec) mysql> DESC perfdata_service_bin; +---------------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------------+-------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | host_name | varchar(75) | NO | MUL | NULL | | | service_description | varchar(75) | NO | | NULL | | | metric | varchar(75) | NO | | NULL | | | ctime | datetime | NO | | NULL | | | value | float | YES | | NULL | | | warn | float | YES | | NULL | | | critical | float | YES | | NULL | | | state | tinyint(4) | YES | | NULL | | +---------------------+-------------+------+-----+---------+----------------+ 9 rows in set (0.00 sec)
下は、ホスト名「localhost」が不要なため、データを削除する例です。
mysql> select * from perfdata_host; +---------+-----------+------------+-------------------+------------------------+------------------------+-------------------+------------------------+------------------------+------------+ | host_id | host_name | group_name | raw_delete_policy | raw_delete_policy_name | raw_delete_policy_type | bin_delete_policy | bin_delete_policy_name | bin_delete_policy_type | is_deleted | +---------+-----------+------------+-------------------+------------------------+------------------------+-------------------+------------------------+------------------------+------------+ | 4 | balancer | NULL | NULL | NULL | user | NULL | NULL | user | 0 | | 2 | localhost | NULL | NULL | NULL | user | NULL | NULL | user | 0 | | 3 | web1 | NULL | NULL | NULL | user | NULL | NULL | user | 0 | | 1 | web2 | NULL | NULL | NULL | user | NULL | NULL | user | 0 | +---------+-----------+------------+-------------------+------------------------+------------------------+-------------------+------------------------+------------------------+------------+ 4 rows in set (0.00 sec) mysql> UPDATE perfdata_host SET is_deleted = 1 WHERE host_name = 'localhost'; Query OK, 1 row affected (0.06 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> exit # /usr/local/nagios/bin/perfparse-db-purge +-----------------------------------------------------------------------------+ | Deleting data flagged for removal. This may take some time. | | Please ensure that NO data for these plugins will be added during deletion. | | Record counts will show below. | +-----------------------------------------------------------------------------+ | Plugins marked for deletion: 00000001 | | Unique Keys marked for deletion: 00000000 | | Metrics marked for deletion: 00000000 | +-----------------------------------------------------------------------------+ | Table: Binary Summary Data, by Plugin deletion. 00000000 | | Table: Binary Summary Header, by Plugin deletion 00000000 | | Table: Raw Summary Data, by Plugin deletion. 00000000 | | Table: Raw Summary Header, by Plugin deletion. 00000006 | | Table: Raw Data, by Plugin deletion. 00000000 | | Table: Binary Data, by Plugin deletion. 00000032 | | Table: Metrics, by Plugin deletion. 00000010 | | Table: Unique Keys, by Plugin deletion. 00000006 | | Table: Plugin, by Plugin deletion. 00000001 | +-----------------------------------------------------------------------------+ | Total Records deleted: 00000055 | +---------------------------------------------------+--------------+----------+ +---------------------------------------------------+--------------+----------+
今日はこんなところで。