AC-5

某SEの雑記帳

Muninの監視項目にMySQLを追加する

      2016/04/07

Muninサーバを構築して、追加監視項目としてApacheを追加しましたがMySQLも監視対象として追加してみたいと思います。
この作業は監視対象のクライアント側だけでの作業です。

プラグインのインストール

MySQLのプラグインのシンボリックリンクを作成します。

[root@test]# ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/mysql_bytes
[root@test]# ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/mysql_queries
[root@test]# ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/mysql_slowqueries
[root@test]# ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/mysql_threads

監視用にMySQLのデータベースとユーザを追加する

[root@test]# mysql -u root -p←MySQLログイン
mysql>
CREATE DATABASE munin;
GRANT SELECT ON munin.* TO munin@localhost IDENTIFIED BY 'password';
FLUSH PRIVILEGES;

設定ファイルにMySQLのログイン情報を記載

[root@test]# vi /etc/munin/plugin-conf.d/munin-node←設定ファイル編集
[mysql*]
env.mysqlopts -u munin --password=password←先ほど作成したユーザ名とパスワードを追加

munin-node再起動と動作テスト

[root@test]# service munin-node restart←munin-node再起動
[root@test]# cd /etc/munin/plugins
[root@test plugins]# /usr/sbin/munin-run mysql_bytes
recv.value 237781
sent.value 320840
[root@test plugins]# /usr/sbin/munin-run mysql_queries
delete.value 0
insert.value 0
replace.value 0
select.value 1384
update.value 0
cache_hits.value 0
[root@test plugins]# /usr/sbin/munin-run mysql_slowqueries
queries.value 0
[root@test plugins]#  /usr/sbin/munin-run mysql_threads
threads.value 1

これでしばらくすると、監視サーバのトップページにMySQLが追加されます。

 - Linux