check_mysql_healthプラグインでコネクション数やSlow Queryを監視できるのでこのプラグインを導入します。
wget http://labs.consol.de/download/shinken-nagios-plugins/check_mysql_health-2.1.8.2.tar.gz tar -xvzf check_mysql_health-2.1.8.2.tar.gz cd check_mysql_health-2.1.8.2 ./configure --with-mymodules-dir=/usr/lib64/nagios/plugins --with-mymodules-dyn-dir=/usr/lib64/nagios/plugins --prefix=/usr/lib64/nagios/plugins make make install mv /usr/lib64/nagios/plugins/libexec/check_mysql_health /usr/lib64/nagios/plugins/
組み込む前に動作を確認してみます。
■接続までの時間を監視
/usr/lib64/nagios/plugins/check_mysql_health --hostname localhost --username nagios --password nagios --socket /tmp/mysql.sock --mode connection-time
■接続数を監視
/usr/lib64/nagios/plugins/check_mysql_health --hostname localhost --username nagios --password nagios --socket /tmp/mysql.sock --mode threads-connected
■Slow Queryを監視
/usr/lib64/nagios/plugins/check_mysql_health --hostname localhost --username nagios --password nagios --socket /tmp/mysql.sock --mode slow-queries
組み込みます。
# vim /etc/nagios/objects/localhost.cfg define service{ use local-service host_name localhost service_description MySQL Connection Time check_command mysql_connection_time!nagios!nagios!/tmp/mysql.sock!0.5!1.0 } define service{ use local-service host_name localhost service_description MySQL Connections check_command mysql_connections!nagios!nagios!/tmp/mysql.sock!10!20 } define service{ use local-service host_name localhost service_description MySQL Slow Query check_command mysql_slow_queries!nagios!nagios!/tmp/mysql.sock!0.1!1.0 } define service{ use local-service host_name localhost service_description MySQL Long Running Proc check_command mysql_long_running_procs!nagios!nagios!/tmp/mysql.sock!1!10 }
# vim /etc/nagios/objects/commands.cfg define command{ command_name mysql_connection_time command_line $USER1$/check_mysql_health --hostname $HOSTADDRESS$ --username $ARG1$ --password $ARG2$ --socket $ARG3$ --mode connection-time --warning $ARG4$ --critical $ARG5$ } define command{ command_name mysql_connections command_line $USER1$/check_mysql_health --hostname $HOSTADDRESS$ --username $ARG1$ --password $ARG2$ --socket $ARG3$ --mode threads-connected --warning $ARG4$ --critical $ARG5$ } define command{ command_name mysql_slow_queries command_line $USER1$/check_mysql_health --hostname $HOSTADDRESS$ --username $ARG1$ --password $ARG2$ --socket $ARG3$ --mode slow-queries --warning $ARG4$ --critical $ARG5$ } define command{ command_name mysql_long_running_procs command_line $USER1$/check_mysql_health --hostname $HOSTADDRESS$ --username $ARG1$ --password $ARG2$ --socket $ARG3$ --mode long-running-procs --warning $ARG4$ --critical $ARG5$ }
パーミッションエラーが発生するケースがあるので、以下のフォルダのパーミッションを変更します。
chmod 777 /var/tmp/check_mysql_health
nagiosを再起動します。
/etc/rc.d/init.d/nagios restart