python MySQL-Slave从服务器状态检测脚本
#!/bin/bashmysql -e "show slave status\G" > mysql_status.txtarray=($(egrep 'Slave_IO_Running|Slave_SQL_Running|Seconds_Behind_Master' mysql_status.txt))if [[ "${array[1]}" == 'Yes' && "${array[3]}" == 'Yes' ]]then if [ "${array[5]}" -eq 0 ] then echo "MySQL slave running OK!" else echo "MySQL slave is behind master ${array[5]} seconds" fielse echo "MySQL slave sync make error" mail -s "MySQL-Slave Error on `uname -n`" 44850823@qq.comfi# -*- coding: utf-8 -*
#! /usr/bin/env python
#
#sudo easy_install fabric
#sudo easy_install paramiko
#fab -f mysql.py check
#[利用Python监测MySQL主从状态](http://hypocritical.blog.51cto.com/3388028/1680778)
#[Python fabric远程自动部署简介](http://lovesoo.org/python-fabric-yuan-cheng-zi-dong-bu-shu-jian-jie.html)
#[自动化运维工具Fabric - 密码管理](http://segmentfault.com/a/1190000000497630)
from fabric.api import *
from fabric.colors import *
from fabric.context_managers import *
from fabric.contrib.console import confirm
import string
import smtplib
import paramiko
#错误日志
#paramiko.util.log_to_file("filename.log")
#client ip
env.user='root'
env.hosts=[
'192.168.60.7',
'192.168.60.61',
]
#env.password='xx'
env.port='22'
#env.user='root'
#env.password='xx'
env.passwords={
'root@192.168.60.7:22':"password",
'root@192.168.60.61:22':"password",
}
#env.mysql_port = '3306'
@task
def check():
slave_ip = run("ip add|grep global")
for ip in env.hosts:
if ip in slave_ip:
slave_ip = ip
slave_io = run("mysql -ustatus -pxx -h"+slave_ip+" -e 'show slave status\G'|grep Slave_IO_Running:|awk '{print $2}'")
slave_sql = run("mysql -ustatus -pxx -h"+slave_ip+" -e 'show slave status\G'|grep Slave_SQL_Running:|awk '{print $2}'")
if slave_io.find('Yes')>=0 and slave_sql.find('Yes') >= 0:
pass
else:
HOST = "smtp.163.com"
SUBJECT = "MySQL Master-Slave Warning . "
TO = "xx@qq.com"
FROM = "xx@163.com"
text = "%-20s MySQL Master-Slave status : down" % slave_ip
BODY = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT ,
"",
text
), "\r\n")
server = smtplib.SMTP()
server.connect(HOST,"25")
server.starttls()
server.login("xx@163.com","password")
server.sendmail(FROM, [TO], BODY)
server.quit()
python MySQL-Slave从服务器状态检测脚本的更多相关文章
- 如何编写LVS对Real Server的健康状态检测脚本
简介:Linux 虚拟服务器(Linux Virtual Server. LVS),是一个由章文松开发的自由软件.利用KVS可以实现高可用的.可伸缩缩的Web, Mail, Cache和Medial等 ...
- MSC服务器-主从检测脚本-check_server_state.sh
说明: 发现keepalived会在凌晨自动进行主从切换,导致msc相关进程运行不稳定: 通过运行check_server_state.sh,及时终止/启动相关进程: 所有脚本使用supervisor ...
- Redis + keepalived 高可用行配置检测脚本
Redis 在生产配置中:除redis集群.哨兵模式之外:主从模式还是比较普遍的. 配置 redis 多主从:由 keepalived 做 VIP 地址漂移.可以实现redis的高可用性. keepa ...
- 查看mysql主从配置的状态及修正 slave不启动问题
1.查看master的状态 mysql> show master status; //Position不应该为0 mysql> show processlist; //state状态应 ...
- Mysql slave 状态之Seconds_Behind_Master
在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...
- MySQL slave状态之Seconds_Behind_Master【转】
在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...
- MySQL slave状态之Seconds_Behind_Master zz
在MySQL的主从环境中,我们可以通过在slave上执行show slave status来查看slave的一些状态信息,其中有一个比较重要的参数Seconds_Behind_Master.那么你是否 ...
- MySQL执行SHOW STATUS查询服务器状态状态之Handler_read_* 详解
在MySQL里,我们一般使用SHOW STATUS查询服务器状态,语法一般来说如下: SHOW [GLOBAL | SESSION] STATUS [LIKE ‘pattern’ | WHERE ex ...
- MySQL slave状态之Seconds_Behind_Master
在MySQL的主从环境中,我们能够通过在slave上运行show slave status来查看slave的一些状态信息,当中有一个比較重要的參数Seconds_Behind_Master.那么你是否 ...
随机推荐
- promise、async和await之执行顺序
async function async1(){ console.log('async1 start') await async2() console.log('async1 end') } asyn ...
- 【转载】 Pytorch(0)降低学习率torch.optim.lr_scheduler.ReduceLROnPlateau类
原文地址: https://blog.csdn.net/weixin_40100431/article/details/84311430 ------------------------------- ...
- jQuery .each()方法与.data()方法
.each(callback): 每次执行传递进来的函数时,函数中的this关键字都指向一个不同的DOM元素(每次都是一个不同的匹配元素).而且,在每次执行函数时,都会给函数传递一个表示作为执行环境的 ...
- JS中数据类型的判断
typeof 使用 : var n = "hello"; console.log(typeof n); console.log(typeof(n));
- 单调栈的运用-bzoj1012(代码转载-http://hzwer.com/1130.html)
Description 现在请求你维护一个数列,要求提供以下两种操作: . 查询操作.语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值.限制:L不超过当前数列的长度. . 插 ...
- 20155208 2006-2007-2 《Java程序设计》第1周学习总结
20155208徐子涵 2016-2017-2 <Java程序设计>第1周学习总结 教材学习内容总结 浏览教材 每章提出自己存在的问题 chapter1:JDK和JRE的区别体现在什么地方 ...
- LSOF查看linux中文件打开情况
如何查看linux中文件打开情况 前言 我们都知道,在linux下,“一切皆文件”,因此有时候查看文件的打开情况,就显得格外重要,而这里有一个命令能够在这件事上很好的帮助我们-它就是lsof. lin ...
- 【HDOJ1045】【DFS】
http://acm.hdu.edu.cn/status.php?user=MekakuCityActors&pid=1045&status=5 Fire Net Time Limit ...
- ionic1实现热更新以版本检测更新安装包的方法
1.需要下载热更新插件:插件名称是cordova-hot-code-push 首先打开cli,执行命令 npm install -g cordova-hot-code-push-cli 此功能主要是为 ...
- Js判断字符的种类
Js判断字符的种类:unicode范围: 48-57:0-9 数字字符 65-90:A-Z 大写字母 97-122: a-z 小写字母 19968-40869:汉字 其他字符 实例:输出 ...