-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_master_slave_status.php
More file actions
40 lines (34 loc) · 955 Bytes
/
check_master_slave_status.php
File metadata and controls
40 lines (34 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env php
<?php
$username = '[root]';
$password = '[master_root_password]';
$servers = array(
'[adprcc3ms_mariadb-master_1]',
'[adprcc3ms_mariadb-slave_1]',
);
$errors = '';
foreach($servers as $server) {
$link = mysql_connect($server, $username, $password);
if($link) {
$res = mysql_query("SHOW SLAVE STATUS", $link);
$row = mysql_fetch_assoc($res);
if($row['Slave_IO_Running'] == 'No') {
$errors .= "Slave IO not running on $server";
$errors .= "Error number: {$row['Last_IO_Errno']}n";
$errors .= "Error message: {$row['Last_IO_Error']}nn";
}
if($row['Slave_SQL_Running'] == 'No') {
$errors .= "Slave SQL not running on $server";
$errors .= "Error number: {$row['Last_SQL_Errno']}n";
$errors .= "Error message: {$row['Last_SQL_Error']}nn";
}
mysql_close($link);
}
else {
$errors .= "Could not connect to $server";
}
}
if($errors) {
mail('[email address]', 'MySQL slave errors', $errors);
}
?>