[CentOS6][Cacti] リモートホストのMySQL監視


Create: 2013/01/21
LastUpdate: 2013/01/23
[ メニューに戻る ]

ここでは、リモートホストで稼動している MSql を監視するように設定します。
Cactiのインストール 」で作成した環境を前提とします。

+-------------+
| localhost   |
|             |
| Cacti       |
+-------------+
+-------------+
| remotehost  |
|             |
| MySql       |
+-------------+

1.リモートホストのMySql に監視用ユーザ作成


リモートホストのMySQLに、監視用のユーザを作成します。
以下の例では、Cactiをインストールしたサーバ(10.34.195.100)からのアクセスのみ許可しています。
ユーザ名は "cacti_watch"、パスワードは、"cactipass" です。
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 38
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> grant process, super on *.* to cacti_watch@'10.34.195.100' identified by 'cactipass';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

2.CactiにMySqlのデータ収集用スクリプトの設置


MySql監視は、percona で公開されている、スクリプトとグラフテンプレートを使用します。
Cacti をインストールしたサーバで、以下のようにアーカイブをダウンロードして展開します。
# wget http://www.percona.com/redir/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.0.1.tar.gz
# tar xvfz percona-monitoring-plugins-1.0.1.tar.gz
スクリプトを Cacti に設置します。
# cp percona-monitoring-plugins-1.0.1/cacti/scripts/ss_get_mysql_stats.php /var/www/cacti/scripts/.
# chown apache.apache /var/www/cacti/scripts/ss_get_mysql_stats.php
"ss_get_mysql_ststs.php" を修正して、デフォルトのユーザを上記1で作成したものに変更します。
このユーザはCacti の画面(データテンプレート)で変更できるのですが、テンプレートがたくさんあるので、プログラムを直接変更します。
もちろん、上記1で作るユーザを、デフォルトの cactiuser にしておけば、プログラムの修正は必要ありません。
# ============================================================================
# CONFIGURATION
# ============================================================================
# Define MySQL connection constants in config.php.  Arguments explicitly passed
# in from Cacti will override these.  However, if you leave them blank in Cacti
# and set them here, you can make life easier.  Instead of defining parameters
# here, you can define them in another file named the same as this file, with a
# .cnf extension.
# ============================================================================
$mysql_user = 'cacti_watch';
$mysql_pass = 'cactipass';
$mysql_port = 3306;
$mysql_ssl  = FALSE;   # Whether to use SSL to connect to MySQL.
スクリプトの動作確認を行います。
以下のように実行して、何かしら値が表示されたらOKです。
"--host" でMySql サーバのIPアドレスを指定します。
# php ./ss_get_mysql_stats.php --host 10.34.195.20 --items hd,he,hf,hi,hl,hn
hd:0 he:18 hf:14 hi:12 hl:151 hn:162

3.グラフテンプレートのインポート 


MySQL用のグラフテンプレートを Cacti にインポートします。
まず、上記2でダウンロードしたアーカイブから "percona-monitoring-plugins-1.0.1/cacti/templates/cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.0.1.xml" を取り出して、PC上に保存します。
次に、ブラウザでCacti の画面を開き、[console]→[Import Template]をクリックし、下図のページが表示されたら、[ファイルを選択]をクリックして、"cacti_host_template_percona_mysql_server_ht_0.8.6i-sver1.0.1.xml" を選択し、[Import]ボタンをクリックします。



下図のページが表示されて、すべて [Success] と表示されていればOKです。



4.監視設定


MySQL用のグラフは、たくさんありますが、ここでは、「 [CentOS6][Cacti] リモートホストの監視を追加する(SNMP使用) 」で作成したリモートホストにMySQLのグラフを1つ追加します。
[console]→[Devvices]→[リモートホスト]をクリックすると、下図のページが表示されます。



[Add Graph Template]メニューで、MySQLのグラフを1つ選択し、[Add]ボタンをクリックします。



[console]→[New Graphs]をクリックすると、下図のページが表示されます。
[Host]メニューで、リモートホストを選択し、上記で追加した MySQLのグラフをチェックして、[Create]ボタンをクリックします。



5.グラフの確認


MySQLのグラフが表示されているか確認します。 [graphs]→[リモートホストのデバイス名]をクリックすると、下図のページが表示されます。 MySQL のデータ収集が始まるまで、しばらく待ち、下図のようなグラフが表示されればOKです。