forked from outlyerapp/plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmysql.replication.py
More file actions
executable file
·50 lines (39 loc) · 1.1 KB
/
mysql.replication.py
File metadata and controls
executable file
·50 lines (39 loc) · 1.1 KB
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
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
"""
Update the MYSQL_USER and MYSQL_PASSWORD variables below.
"""
import subprocess
import re
import sys
MYSQL_USER = ''
MYSQL_PASSWORD = ''
command = ['/usr/bin/mysql', '-t', '-E', '-N', '-s', '--column-names', '-e', "show slave status"]
if MYSQL_USER:
command.append('-u%s' % MYSQL_USER)
if MYSQL_PASSWORD:
command.append('-p%s' % MYSQL_PASSWORD)
try:
slave_status = subprocess.check_output(command)
except:
print "Plugin Failed!"
sys.exit(2)
output = "OK | "
slave_metric_list = slave_status.split('\n')
repl_status=0
stats_count=0
for line in slave_metric_list:
if line and ':' in line:
stats_count = 1
metric = line.split(':')
k = metric[0].strip().lower()
v = metric[1].strip()
output += k + '=' + v + ';;;; '
if k in ('slave_io_running','slave_sql_running'):
if v == 'No':
print '%s appears to be false!' %k
repl_status += 1
if stats_count < 1:
print "This server does not appear to be a replication slave!"
sys.exit(1)
print output
sys.exit(repl_status)