A MySql master-salve replication lag time checker tool implementation by PHP more like pt-heartbeat.
Download this project zip file and deploy on your any one php machine which can access MySql server.
Change the setting.php
according to your actual situation.
<?php
/**
* Default setting sample
*
*/
return [
'mysqlMasterHost' => '', // Write server host
'mysqlMasterUser' => '',
'mysqlMasterPwd' => '',
'mysqlSlaveHosts' => [], // Slaves host of the master
'mysqlSlaveUser' => '', // Read server username
'mysqlSlavePwd' => '',
'interval' => 1, // Frequency for update monitor time in seconds
'averages' => [1, 5, 30], // Latest period slave lagging average time in seconds, can be more than three and even more, su as [1, 5, 30, 60 ...]
'logFilePath' => '/val/logs/',
'logFileName' => 'HeartbeatOne-Monitor',
'mysqlDriver' => 'mysqli', // Only support `mysqlli` or `PDO` driver
];
Import heartbeat.sql
to your MySQl master server which you want tracing.
Just run following command in cli, you can see dealy time report and wirte to log in the meanwhile if everything is ok.
php heartbeat.php
For the production suggest run in background then only wirte delay data to log file.
nohup php heartbeat.php > /dev/null &
- Notice! The monitor log content will be clear every 24hours