Use nagios to monitor a mysql-replication 3


I´ve already pointed out here, that you can easily restart a replication. But you have to know that the replication isn´t working. Instead of continuously typing "CHECK SLAVE STATUS\G" in mysql i´ve decided to use nagios for that. If something is wrong, i get a mail and a notification in firefox.

For the monitoring i use check_mysql_health.

You can do much more with it. But this describes the replication-monitoring. 😉

At the end slave-io (is the IO-thread running?), slave-sql (is the SQL-thread running?), and slave-lag (delay between the servers) will be checked.

My different nagios-configs for the localohost are stored in /usr/local/nagios/etc/objects/localhost. Nagios loads all configs on start, if the folder is defined in /usr/local/nagios/etc/nagios.cfg

cfg_dir=/usr/local/nagios/etc/objects/localhost

The mysql-checks are defined in /usr/local/nagios/etc/objects/localhost/mysql.cfg.

define command{

command_name check_mysql_health

command_line $USER1$/check_mysql_health -mode $ARG1$ --username $USER3$ --password $USER4$ --warn $ARG2$ --crit $ARG3$ --hostname $HOSTNAME$

}

define service{

use important-service

service_description MYSQL slave-io

host_name obelix.schaal-24.de

check_command check_mysql_health!slave-io-running

}

define service{

use important-service

service_description MYSQL slave-sql

host_name obelix.schaal-24.de

check_command check_mysql_health!slave-sql-running

}

define service{

use important-service-graph

service_description MYSQL slave-lag

host_name obelix.schaal-24.de

check_command check_mysql_health!slave-lag!10!60

}

The values for $USERX$ are stored in /usr/local/nagios/etc/resource.cfg:

# Sets $USER1$ to be the path to the plugins

$USER1$=/usr/local/nagios/libexec

# mysql-passwords

$USER3$=nagios

$USER4$=SECRET_PASSWORD

I use a new user for the checks, since he only needs some rights for the sql-checks and i can easily check different sql-servers from nagios without changing the configfiles too much.

important-service and important-service-graph are extensions to the generic-service and are also defined in /usr/local/nagios/etc/objects/templates.cfg

define service{

name important-service

use generic-service

max_check_attempts 3

normal_check_interval 1

retry_check_interval 1

register 0

}

define service{

name important-service-graph

use important-service

notes Graph

notes_url /nagios/display_nagios_info.php?name1=$HOSTNAME$&name2=$SERVICEDESC$

}

To monitor a remote sql-server just change the hostname, since the pluging connects direct to mysql. There is no need for nrpe or anything else.

define service{

use important-service

service_description MYSQL slave-io

host_name idefix.schaal-24.de

check_command check_mysql_health!slave-io-running

}


Leave a comment

Your email address will not be published. Required fields are marked *

3 thoughts on “Use nagios to monitor a mysql-replication