Check mysql-replica-status¶
Overview¶
Checks the replication status of a MySQL/MariaDB replica: I/O thread state, SQL thread state, replication lag (Seconds_Behind_Master / Seconds_Behind_Source), read_only mode, semi-synchronous replication mode and (on MariaDB 10.5+) parallel replication settings. Also reports whether this server is a Galera node and how many downstream replicas it is feeding. Can safely be run against standalone servers; it reports „This is a standalone server.“
Important Notes:
On MariaDB 10.5+,
REPLICATION CLIENTwas split.SHOW REPLICA STATUS/SHOW SLAVE STATUSrequiresSLAVE MONITOR(or its MariaDB 11+ aliasREPLICA MONITOR); plainREPLICATION CLIENTalone is not enough on those versions. GrantSLAVE MONITOR(orREPLICA MONITOR) to be safe.
Data Collection:
Queries
SHOW GLOBAL VARIABLESfor replication-related settings (binlog_format,read_only,rpl_semi_sync_*,slave_parallel_threads/replica_parallel_threads,slave_parallel_mode/replica_parallel_mode,wsrep_on,wsrep_provider_options).Executes
SHOW REPLICA STATUS(orSHOW SLAVE STATUSon older versions) andSHOW SLAVE HOSTS.The IO/SQL thread state, lag, parallel-replication and semi-sync checks use the MariaDB 10.5+ field names first (
Replica_*,replica_parallel_*,rpl_semi_sync_source_enabled, etc.) and fall back to the legacySlave_*/*master*names. Whichever the server exposes is used.Logic is taken from MySQLTuner script:get_replication_status(), verified in sync with v2.8.41.
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 Interval Recommendation |
Every minute |
Can be called without parameters |
Yes |
Runs on |
Cross-platform |
Compiled for Windows |
No |
Requirements |
User with |
3rd Party Python modules |
|
Help¶
usage: mysql-replica-status [-h] [-V] [--always-ok]
[--defaults-file DEFAULTS_FILE]
[--defaults-group DEFAULTS_GROUP]
[--lag-warning LAG_WARN] [--lag-critical LAG_CRIT]
[--severity {warn,crit}] [--timeout TIMEOUT]
Checks the replication status of a MySQL/MariaDB replica: I/O thread state,
SQL thread state, replication lag (`Seconds_Behind_Master` /
`Seconds_Behind_Source`), `read_only` mode, semi-synchronous replication mode
and (on MariaDB 10.5+) parallel replication settings. Also reports whether
this server is a Galera node and how many downstream replicas it is feeding.
Alerts when replication is broken, configured but not running, or lagging
behind.
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
--lag-warning LAG_WARN
Seconds of replication lag at which the WARN flag is
raised. A value of 0 means any lag (the historic
default; matches the mysqltuner cut-off). Default: 0
--lag-critical LAG_CRIT
Seconds of replication lag at which the CRIT flag is
raised. If omitted, lag never escalates to CRIT.
--severity {warn,crit}
Severity for alerts that do not depend on thresholds
(IO/SQL thread not running, `read_only` disabled). 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 (OK, standalone server):
Everything is ok. Galera synchronous replication: NO. `binlog_format` is `ROW`. `innodb_support_xa` is `ON`. Semi-sync primary: not activated. Semi-sync replica: not activated. This is a standalone server.
Output (WARN, replica not running):
Galera synchronous replication: NO. `binlog_format` is `ROW`. `innodb_support_xa` is `ON`. Semi-sync primary: not activated. Semi-sync replica: not activated. Replica is not running but seems to be configured (IO: `No`, SQL: `Yes`) [WARNING]. Parallel replication: disabled.
Recommendations:
* Investigate the IO/SQL thread errors via `SHOW REPLICA STATUS` (look at `Last_IO_Error`, `Last_SQL_Error`)
* Set `replica_parallel_threads` to the number of vCPUs to enable parallel replication
States¶
WARN or CRIT (per
--severity) if the replica is configured but the IO or SQL thread is not running.WARN or CRIT (per
--severity) if the replica is running withread_only=OFF.Lag (
Seconds_Behind_Master/Seconds_Behind_Source):WARN when lag >
--lag-warningseconds (default 0, i.e. any lag).CRIT when lag >=
--lag-criticalseconds (no default; lag never escalates to CRIT unless this is set).WARN when both
Seconds_Behind_MasterandSeconds_Behind_Sourceare NULL (replication thread reports unknown lag, usually a sign of recovery).
WARN or CRIT (per
--severity) on MariaDB 10.5+ if parallel replication is enabled with a non-optimisticmode.--always-oksuppresses all alerts and always returns OK.
Perfdata / Metrics¶
Name |
Type |
Description |
|---|---|---|
mysql_replication_io_running |
Number |
|
mysql_replication_seconds_behind |
Seconds |
Replication lag from |
mysql_replication_slave_count |
Number |
Number of downstream replicas reading from this server (from |
mysql_replication_sql_running |
Number |
|
Credits, License¶
Authors: Linuxfabrik GmbH, Zurich
License: The Unlicense, see LICENSE file.
Credits:
heavily inspired by MySQLTuner (https://github.com/major/MySQLTuner-perl)