python检测mysql状态脚本--参考
来源:互联网 发布:国通交规软件下载 编辑:程序博客网 时间:2024/06/06 08:59
#!/usr/bin/env python
#encoding:utf-8
import
MySQLdb
import
paramiko
import
sys,os
from
email.mime.text
import
MIMEText
from
email.header
import
Header
import
smtplib
db1_ip
=
"172.17.2.51"
db2_ip
=
"172.17.2.52"
num
=
''
mmm_info
=
''
IoS
=
''
SqS
=
''
Sec
=
''
e
=
''
def
db_info(ip):
global
IoS
global
SqS
global
Sec
global
e
try
:
conn
=
MySQLdb.connect(host
=
ip,user
=
'test'
,passwd
=
'123456'
,port
=
7000
,charset
=
'utf8'
)
cur
=
conn.cursor()
cur.execute(
'show slave status'
)
for
n
in
cur.fetchall():
IoS
=
n[
10
]
SqS
=
n[
11
]
Sec
=
n[
32
]
cur.close()
conn.close()
except
MySQLdb.Error,e:
print
"MySQLdb Error"
,e
def
send_mail(INFO):
to
=
"494379480@qq.com"
user
=
"liyiliangyw@feinno.com"
passwd
=
"xxxxxx"
subject
=
'辽宁移动企业通信录数据库故障警告'
mail_host
=
"smtp.feinno.com"
port
=
'587'
content
=
INFO
msg
=
MIMEText(content,_subtype
=
'plain'
,_charset
=
'utf-8'
)
msg[
'To'
]
=
to
msg[
'from'
]
=
user
msg[
'Subject'
]
=
Header(subject,
'utf-8'
)
s
=
smtplib.SMTP()
s.connect(mail_host,port)
s.login(user,passwd)
s.sendmail(user,to,msg.as_string())
s.close()
def
mmm_status():
global
num
global
mmm_info
host
=
db2_ip
user
=
'root'
password
=
'xxxxxx'
cmd
=
'mmm_control show'
s
=
paramiko.SSHClient()
s.load_system_host_keys()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect(host,
22
,user,password,timeout
=
1
)
stdin,stdout,stderr
=
s.exec_command(cmd)
cmd_result
=
stdout.read(),stderr.read()
mmm_info
=
str
(
list
(cmd_result)[
0
])
def
run(IP):
mmm_status()
db_info(IP)
if
e
=
=
"":
if
IoS !
=
"Yes"
or
SqS !
=
"Yes"
:
DB_info
=
'%s replicaiton error! \nSlave_IO_Running:%s\nSlave_SQL_Running:%s\nSeconds_Behind_Master:%s\n'
'\n%s'
%
(IP,IoS,SqS,Sec,mmm_info)
send_mail(DB_info)
else
:
DB_info
=
'%s mysql_db is not ok ,info:%s'
%
(IP,e)
send_mail(DB_info)
run(db1_ip)
run(db2_ip)
阅读全文
0 0
- python检测mysql状态脚本--参考
- 检测mysql状态脚本
- 轻松接触一个检测MySQL状态的脚本
- 批量检测Mysql复制状态的shell 脚本
- Tomcat 运行状态检测脚本
- mysql 复制检测脚本
- 数据库知识:带你轻松接触一个检测mysql状态脚本
- mysql 检测从库状态
- Linux 脚本循环检测网络状态
- 定时检测服务状态脚本实现
- windows下检测软件运行状态。脚本
- shell脚本---mysql检测监控脚本系列
- python连接mysql脚本
- Python 执行MySQL 脚本
- python 备份mysql脚本
- mysql主从数据库状态检测(php)
- python脚本检测linux进程是否运行
- python之cpu性能检测脚本
- Shiro的URL匹配规则(AntPathMatcher)
- Scala入门到精通——第九节 继承与组合
- 《More Effective C++》条款27:如何让类对象只在栈(堆)上分配空间?
- Tomcat内存溢出解决办法
- zigbee学习笔记---Channel、PANID、发射功率及其它参数
- python检测mysql状态脚本--参考
- Java内存模型
- 20170629
- 逆向入门(一)
- float浮点数0.0和1.0在计算机内存中是怎么存的?
- Maven入门指南
- JavaFx入门教程(二)
- 单一职责原则
- 属性word-wrap与word-break的区别