check_rep.php if (Empty ($_request["key"])) Die (':) missing key '); if ($_request["key"]! = ' Xupeng ') die (':) error key '); Include ("mysql_instance.php"); Include ("check_status_api.php"); Define ("USERNAME", "User name"); Define ("PASSWORD", "password"); Define ("DebugMode", false); $instances = Get_instances (); if ($instances) { Echo << END; echo " n "; if (! DebugMode) { echo " n "; }else{ echo " n "; } foreach ($instances as $host) { $res = Check_mysql_replication_status ($host, USERNAME, PASSWORD); if (! DebugMode) { Switch ($res ["result"]) { Case-4: $memo = "Unknown exception"; Break Case-3: $memo = "Query Failed"; Break Case-2: $memo = "Unable to connect to port"; Break Case-1: $memo = "State Unknown"; Break Case 0: $memo = "OK"; Break Case 1: $memo = "Synchronization Failed"; if ($res ["slave_io_running"] <> "Yes") { $memo. = $res ["Last_io_error"]. "(" . $res ["Last_io_errno"]. ")"; } if ($res ["slave_sql_running"] <> "Yes") { $memo. = $res ["Last_sql_error"]. "(" . $res ["Last_sql_errno"]. ")"; } Break Case 2: $memo = "Database not set synchronization"; Break } echo " n "; }else{ echo " n "; } } echo "
Instance |
Result |
Slave_io_running |
Slave_sql_running |
Master_host |
Master_port |
replicate_do_db |
Memo |
Instance |
Result |
Slave_io_running |
Slave_sql_running |
Master_host |
Master_port |
replicate_do_db |
Slave_io_state |
Last_io_errno |
Last_io_error |
Last_sql_errno |
Last_sql_error |
{$host} |
{$res [' result ']} |
{$res [' slave_io_running ']} |
{$res [' slave_sql_running ']} |
{$res [' Master_host ']} |
{$res [' Master_port ']} |
{$res [' replicate_do_db ']} |
{$memo} |
{$host} |
{$res [' result ']} |
{$res [' slave_io_running ']} |
{$res [' slave_sql_running ']} |
{$res [' Master_host ']} |
{$res [' Master_port ']} |
{$res [' replicate_do_db ']} |
{$res [' slave_io_state ']} |
{$res [' Last_io_errno ']} |
{$res [' Last_io_error ']} |
{$res [' Last_sql_errno ']} |
{$res [' Last_sql_error ']} |
n "; Echo <<END; }else{ Die ("No MySQL instances defined."); } check_status_api.php !--? php /* * Check the synchronization status of the MySQL server */ Function check_mysql_replication_status ($host, $username, $ Password) { //default state unknown $r = Array ( "result" = 1 ); try{ $dbh = @mysql_connect ($host, $userna Me, $password); if (! $dbh) { //cannot connect to $r ["result"] =-2; return ($R); } $query = "SHOW SLAVE STATUS"; $res = @mysql_query ($query, $DBH); $err = @mysql_error (); if ($err) { //cannot connect to $r ["result"] =-3; return ($R); } $row = mysql_fetch_array ($res); $r = $row; if ($r ["slave_io_running"] = = "Yes") && ($r ["slave_sql_running"] = = "Yes") { $r ["result"] = 0; } else{ if (!empty ($row)) { $r ["result"] = 1; } else{ $r ["result"] = 2; } } }catch (Exception $e) { $r ["result"] =-4; } return ($R); } mysql_instance.php |