Check mysql-replica-status

Overview

Checks the replication status of a MySQL/MariaDB replica, including I/O thread state, SQL thread state, seconds behind master, and replication errors. Can also be run against standalone servers (reports that no replication is configured). Reports Galera synchronous replication state, binlog format, semi-synchronous replication configuration, and XA support.

Important Notes:

Data Collection:

  • Queries SHOW GLOBAL VARIABLES for replication-related settings (binlog_format, read_only, rpl_semi_sync_*, wsrep_on, wsrep_provider_options, etc.)

  • Executes SHOW REPLICA STATUS (or SHOW SLAVE STATUS on older versions) and SHOW SLAVE HOSTS

  • Logic is taken from MySQLTuner script:get_replication_status(), v1.9.8

Fact Sheet

Fact

Value

Check Plugin Download

https://github.com/Linuxfabrik/monitoring-plugins/tree/main/check-plugins/mysql-replica-status

Nagios/Icinga Check Name

check_mysql_replica_status

Check Interval Recommendation

Every minute

Can be called without parameters

Yes

Runs on

Cross-platform

Compiled for Windows

No

3rd Party Python modules

pymysql

Help

usage: mysql-replica-status [-h] [-V] [--always-ok]
                            [--defaults-file DEFAULTS_FILE]
                            [--defaults-group DEFAULTS_GROUP]
                            [--severity {warn,crit}] [--timeout TIMEOUT]

Checks the replication status of a MySQL/MariaDB replica, including I/O thread
state, SQL thread state, seconds behind master, and replication errors. Alerts
when replication is broken or lagging.

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  --always-ok           Always returns OK.
  --defaults-file DEFAULTS_FILE
                        MySQL/MariaDB cnf file to read user, host and password
                        from. Example: `--defaults-
                        file=/var/spool/icinga2/.my.cnf`. Default:
                        /var/spool/icinga2/.my.cnf
  --defaults-group DEFAULTS_GROUP
                        Group/section to read from in the cnf file. Default:
                        client
  --severity {warn,crit}
                        Severity for alerts that do not depend on thresholds.
                        One of "warn" or "crit". Default: warn
  --timeout TIMEOUT     Network timeout in seconds. Default: 3 (seconds)

Usage Examples

./mysql-replica-status --defaults-file=/var/spool/icinga2/.my.cnf

Output:

Galera Synchronous replication: NO. Binlog format: ROW, XA support enabled: ON. Semi synchronous Primary: Not Activated. Semi synchronous Replica: Not Activated. This Replica is not running but seems to be configured [WARNING].

States

  • WARN or CRIT (depending on --severity) if the replica is not running but seems to be configured.

  • WARN or CRIT (depending on --severity) if the replica is running with read_only disabled.

  • WARN or CRIT (depending on --severity) if the replica is lagging behind the primary.

  • --always-ok suppresses all alerts and always returns OK.

Perfdata / Metrics

There is no perfdata.

Credits, License