muninでMySQLの情報を取得する
次の三つを参考にさせてもらいました。一つ目は基本の手順、二つ目はinnodbとか他の情報を取得できるプラグインの追加手順、三つ目も別のプラグインの追加手順がありました。
http://t.nzk.me/entry/2012/12/16/005311
環境
前提
innodbの情報を取得するので、MySQLは5.5系です。CentOSのベースリポジトリにあるのは5.1系なので、remiから取得します。
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
yum install --enablerepo=remi -y mysql mysql-server mysql-devel
chkconfig mysqld on
service mysqld start
手順
- 必要なパッケージをインストールする
yum install --enablerepo=remi -y mysql-devel
yum install -y --enablerepo=epel perl-IPC-ShareLite perl-Cache-Cache perl-Cache perl-DBD-Mysql - プラグインを追加する
ln -s /usr/share/munin/plugins/mysql_bytes /etc/munin/plugins/
ln -s /usr/share/munin/plugins/mysql_queries /etc/munin/plugins/
ln -s /usr/share/munin/plugins/mysql_slowqueries /etc/munin/plugins/
ln -s /usr/share/munin/plugins/mysql_threads /etc/munin/plugins/
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_commands
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_innodb_bpool
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_innodb_io
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_innodb_log
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_innodb_tnx
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_select_types
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_table_locks
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_connections
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_slow
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_network_traffic
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_qcache
ln -s /usr/share/munin/plugins/mysql_ /etc/munin/plugins/mysql_qcache_mem - mysqlにmuninからの監視権限を設定する
たとえば次の通り。もしmysql_bytes、mysql_querysだけなら、特定のスキーマに対してselect権限をつけるだけでよい。grant all on *.* to munin@localhost identified by 'munin';
- munin nodeからmysqlに接続する設定をする
/etc/munin/plugin-conf.d/munin-node ファイルに次の記述を追加する。[mysql*]
env.mysqlopts -umunin --password=munin
env.mysqlconnection DBI:mysql:mysql;host=localhost;port=3306
env.mysqluser munin
env.mysqlpassword munin - munin nodeを再起動する
service munin-node restart
MySQLは再起動しなくていいけど、情報取得に少し時間がかかります。