标签:监控redis和zookpeer服务脚本 python脚本
监控rediszookpeer
#!/bin/bash name=`cat /etc/salt/minion | grep "^id" | awk ‘{print $2}‘` ipaddr=`/sbin/ifconfig | grep "inet addr" | egrep -v "10\.|127\." | awk -F‘[: ]+‘ ‘{print $4}‘` function checkRedis(){ ps="`ps -ef | grep redis-server | grep -v grep | wc -l`" nets=`netstat -lntup|grep redis|wc -l` num=`cat /tmp/redis.log` if [ $ps -lt 1 -o $nets -lt 1 ] then if [ $num -eq 0 ];then echo 1 > /tmp/redis.log python python_email.py "ip addr:${ipaddr} salt-minion:${name} redisd is down" "PROBLEM: redis" fi elif [ $ps -gt 0 -a $nets -gt 0 ] then if [ $num -eq 1 ];then echo 0 > /tmp/redis.log python python_email.py "ip addr:${ipaddr} salt-minion:${name} redisd is ok" "OK:redis" fi fi } function checkZk(){ ps=`ps -ef|grep zookeeper|grep -v grep|wc -l` nets=`netstat -lntup|grep java|wc -l` num=`cat /tmp/zookeeper.log` if [ $ps -lt 1 -o $nets -lt 1 ] then if [ $num -eq 0 ];then echo 1 > /tmp/zookeeper.log python python_email.py "ip addr:${ipaddr} salt-minion:${name} zookeeperd is down" "PROBLEM: zookeeper" fi elif [ $ps -gt 0 -a $nets -gt 0 ] then if [ $num -eq 1 ];then echo 0 > /tmp/zookeeper.log python python_email.py "ip addr:${ipaddr} salt-minion:${name} zookeeperd is ok" "OK:zookeeper" fi fi } checkRedis #checkZk
python脚本
#!/usr/bin/python # -*- coding: utf-8 -*- import sys def smtp(file,text): from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import smtplib #加邮件头 msg=MIMEText(file,_charset=‘utf-8‘) to_list=[‘xxxx@qq.com‘,‘xxx@163.com‘,‘xxx@xx.com‘] msg[‘from‘] = ‘xxxx@qq.com‘ msg[‘subject‘] = text #发送邮件 try: server = smtplib.SMTP() server.connect(‘smtp.exmail.qq.com‘) server.login(‘xxxx@qq.com‘,‘xxxxx‘)#XXX为用户名,XXXXX为密码 server.sendmail(msg[‘from‘],to_list,msg.as_string()) server.quit() print ‘发送成功‘ except Exception, e: print str(e) if __name__ == ‘__main__‘: smtp(sys.argv[1],sys.argv[2])
本文出自 “奋斗吧” 博客,转载请与作者联系!
监控redis和zookpeer服务脚本 并且python发送邮件
标签:监控redis和zookpeer服务脚本 python脚本
原文地址:http://lvnian.blog.51cto.com/7155281/1774415