#!/bin/env python
#-*-coding:utf-8-*-
from datetime import *
import global_functions as func
def get_alarm_mysql_status():
sql="select a.application_id,a.server_id,a.create_time,a.connect,a.connections,a.active,b.send_mail,b.alarm_connections,b.alarm_active,b.threshold_connections,b.threshold_active from mysql_status a, servers b where a.server_id=b.id;"
result=func.mysql_query(sql)
if result <> 0:
for line in result:
application_id=line[0]
server_id=line[1]
create_time=line[2]
connect=line[3]
connections=line[4]
active=line[5]
send_mail=line[6]
alarm_connections=line[7]
alarm_active=line[8]
threshold_connections=line[9]
threshold_active=line[10]
if connect <> "success":
sql="insert into alarm(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail) values(%s,%s,%s,%s,%s,%s,%s,%s,%s);"
param=(application_id,server_id,create_time,'mysql','connect',connect,'error','数据库服务器连接失败',send_mail)
func.mysql_exec(sql,param)
else:
if int(alarm_connections)==1:
if int(connections)>=int(threshold_connections):
sql="insert into alarm(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail) values(%s,%s,%s,%s,%s,%s,%s,%s,%s);"
param=(application,server_id,create_time,'mysql','connections',connections,'warning','数据库总连接数过多',send_mail)
func.mysql_exec(sql,param)
if int(alarm_active)==1:
if int(active)>=int(threshold_active):
sql="insert into alarm(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail) values(%s,%s,%s,%s,%s,%s,%s,%s,%s);"
param=(application,server_id,create_time,'mysql','active',active,'warning','数据库活动连接过多',send_mail)
func.mysql_exec(sql,param)
else:
pass
def get_alarm_mysql_replcation():
sql="select a.application_id,a.server_id,a.create_time,a.slave_io_run,a.slave_sql_run,a.delay,b.send_mail,b.alarm_repl_status,b.alarm_repl_delay,b.threshold_repl_delay from mysql_replication a,servers b where a.server_id=b.id and a.is_slave='1';"
result=func.mysql_query(sql)
if result <> 0:
for line in result:
application=line[0]
server_id=line[1]
create_time=line[2]
slave_io_run=line[3]
slave_sql_run=line[4]
delay=line[5]
send_mail=line[6]
alarm_repl_status=line[7]
alarm_repl_delay=line[8]
threshold_repl_delay=line[9]
if alarm_repl_status==1:
if (slave_io_run== "Yes") and (slave_sql_run== "Yes"):
if alarm_repl_delay=="yes":
if int(delay)>=int(threshold_repl_delay):
sql="insert into alarm(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail) values(%s,%s,%s,%s,%s,%s,%s,%s,%s);"
param=(application,server_id,create_time,'mysql','delay',delay,'warning','数据库备库延时',send_mail)
func.mysql_exec(sql,param)
else:
sql="insert into alarm(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail) values(%s,%s,%s,%s,%s,%s,%s,%s,%s);"
param=(application,server_id,create_time,'mysql','replication','IO Thread:'+slave_io_run+',SQL Thread:'+slave_sql_run,'error','数据库同步进程停止',send_mail)
func.mysql_exec(sql,param)
else:
pass
def send_alarm_mail():
sql="select alarm.application_id,app.display_name application,alarm.server_id,servers.host,servers.port,alarm.create_time,db_type,alarm_type,alarm_value,level,message,alarm.send_mail from alarm left join servers on alarm.server_id=servers.id left join application app on servers.application_id=app.id;"
result=func.mysql_query(sql)
if result <> 0:
send_alarm_mail = func.get_option('send_alarm_mail')
mail_to_list = func.get_option('mail_to_list')
mailto_list=mail_to_list.split(';')
for line in result:
application_id=line[0]
application=line[1]
server_id=[2]
host=line[3]
port=line[4]
create_time=line[5]
db_type=line[6]
alarm_type=line[7]
alarm_value=line[8]
level=line[9]
message=line[10]
send_mail=line[11]
if send_alarm_mail=="1":
if send_mail==1:
mail_subject=message+' 当前值:'+alarm_value+' 服务器:'+application+'-'+host+':'+port+' 时间:'+create_time.strftime('%Y-%m-%d %H:%M:%S')
mail_content="please check!"
result = func.send_mail(mailto_list,mail_subject,mail_content)
if result:
send_mail_status=1
else:
send_mail_status=0
else:
send_mail_status=0
else:
send_mail_status=0
if send_mail_status==1:
func.mysql_exec("insert into alarm_history(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail,send_mail_status) select application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail,1 from alarm;",'')
elif send_mail_status==0:
func.mysql_exec("insert into alarm_history(application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail,send_mail_status) select application_id,server_id,create_time,db_type,alarm_type,alarm_value,level,message,send_mail,0 from alarm;",'')
func.mysql_exec("delete from alarm",'')
else:
pass
if __name__ == '__main__':
get_alarm_mysql_status()
get_alarm_mysql_replcation()
send_alarm_mail()
没有合适的资源?快使用搜索试试~ 我知道了~
MySQLMTOP.zip
共478个文件
php:207个
js:92个
png:73个
需积分: 10 6 下载量 46 浏览量
2019-01-25
23:14:46
上传
评论
收藏 1.7MB ZIP 举报
温馨提示
MySQLMTOP是一个由Python+PHP开发的MySQL企业级监控系统。系统由Python实现多进程数据采集和告警,PHP实现WEB展示和管理。最重要是MySQL服务器无需安装任何Agent,只需在监控WEB界面配置相关数据库信息 功能非常强大: 可对上百台MySQL数据库的状态、连接数、QTS、TPS、数据库流量、复制、性能等进行时时监控
资源推荐
资源详情
资源评论
收起资源包目录
MySQLMTOP.zip (478个子文件)
bootstrap.css 130KB
bootstrap.min.css 103KB
flat-ui.css 70KB
jquery-ui-1.10.0.custom.css 61KB
jquery-ui-1.9.2.custom.css 60KB
bootstrap-responsive.css 23KB
font-awesome.css 22KB
font-awesome.min.css 17KB
layout.css 17KB
bootstrap-responsive.min.css 16KB
bootstrap-switch.css 15KB
jquery.jqplot.css 6KB
jquery.contextMenu.css 4KB
datepicker.css 4KB
datepicker.css 4KB
jquery.jqplot.min.css 3KB
style.css 3KB
colorpicker.css 3KB
flat-ui-fonts.css 3KB
prettify.css 846B
ie.css 696B
jquery.ui.1.10.0.ie.css 523B
jquery.ui.1.9.2.ie.css 523B
WdatePicker.css 158B
fontawesome-webfont.eot 25KB
img.gif 2KB
img.gif 2KB
chart.gif 1KB
datePicker.gif 1KB
colorpicker_indic.gif 86B
custom_indic.gif 86B
colorpicker_select.gif 78B
blank.gif 49B
.htaccess 13B
.htaccess 13B
My97DatePicker.htm 1KB
test.html 3KB
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
index.html 123B
favicon.ico 1KB
favicon.ico 1KB
config.ini 406B
bg.jpg 307B
jquery.jqplot.js 467KB
jquery-ui-1.9.2.custom.min.js 232KB
jquery-ui-1.10.0.custom.min.js 222KB
jquery.jqplot.min.js 168KB
jquery.js 93KB
jquery-1.8.3.min.js 91KB
jquery-1.9.0.min.js 91KB
bootstrap.js 63KB
jquery.contextMenu.js 61KB
jqplot.cursor.js 46KB
Chart.js 45KB
jqplot.canvasOverlay.js 45KB
jqplot.meterGaugeRenderer.js 43KB
jqplot.funnelRenderer.js 40KB
jqplot.pieRenderer.js 36KB
jqplot.barRenderer.js 35KB
jqplot.donutRenderer.js 34KB
jqplot.bubbleRenderer.js 31KB
jqplot.dateAxisRenderer.js 30KB
jqplot.pyramidAxisRenderer.js 30KB
jqplot.categoryAxisRenderer.js 29KB
bootstrap.min.js 28KB
jqplot.mekkoAxisRenderer.js 26KB
jqplot.canvasTextRenderer.js 24KB
jqplot.pyramidGridRenderer.js 22KB
jqplot.logAxisRenderer.js 22KB
共 478 条
- 1
- 2
- 3
- 4
- 5
资源评论
运维小辉
- 粉丝: 14
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功