#!/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()
没有合适的资源?快使用搜索试试~ 我知道了~
MySQL MTOP是一个由Python+PHP开发的开源MySQL数据库监控系统
共482个文件
php:207个
js:92个
png:73个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 59 浏览量
2023-06-15
16:39:59
上传
评论
收藏 1.99MB ZIP 举报
温馨提示
MySQL MTOP是一个由Python+PHP开发的开源MySQL数据库监控系统。系统由Python实现多进程数据采集和告警,PHP实现WEB展示和管理。MySQL服务器无需安装任何Agent,只需在监控WEB界面配置相关数据库信息,启动监控进程后,即可对上百台MySQL数据库的状态、连接数、QTS、TPS、数据库流量、复制、性能慢查询等进行时时监控。并能在数据库偏离设定的正常运行阀值(如连接异常,复制异常,复制延迟) 时发送告警邮件通知到DBA进行处理。并对历史数据归档,通过图表展示出数据库近期状态,以便DBA和开发人员能对遇到的问题进行分析和诊断。
资源推荐
资源详情
资源评论
收起资源包目录
MySQL MTOP是一个由Python+PHP开发的开源MySQL数据库监控系统 (482个子文件)
bootstrap.css 124KB
bootstrap.min.css 103KB
flat-ui.css 67KB
jquery-ui-1.10.0.custom.css 59KB
jquery-ui-1.9.2.custom.css 58KB
bootstrap-responsive.css 22KB
font-awesome.css 21KB
font-awesome.min.css 17KB
bootstrap-responsive.min.css 16KB
layout.css 16KB
bootstrap-switch.css 14KB
jquery.jqplot.css 5KB
jquery.contextMenu.css 4KB
datepicker.css 4KB
jquery.jqplot.min.css 3KB
datepicker.css 3KB
style.css 3KB
colorpicker.css 3KB
flat-ui-fonts.css 3KB
googlefonts.css 1KB
prettify.css 817B
ie.css 653B
jquery.ui.1.10.0.ie.css 507B
jquery.ui.1.9.2.ie.css 507B
WdatePicker.css 149B
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 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
index.html 114B
favicon.ico 1KB
favicon.ico 1KB
config.ini 406B
bg.jpg 307B
jquery.jqplot.js 456KB
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 60KB
jquery.contextMenu.js 60KB
jqplot.cursor.js 45KB
jqplot.canvasOverlay.js 44KB
Chart.js 43KB
jqplot.meterGaugeRenderer.js 42KB
jqplot.funnelRenderer.js 39KB
jqplot.pieRenderer.js 35KB
jqplot.barRenderer.js 34KB
jqplot.donutRenderer.js 33KB
jqplot.bubbleRenderer.js 30KB
jqplot.dateAxisRenderer.js 30KB
jqplot.pyramidAxisRenderer.js 29KB
jqplot.categoryAxisRenderer.js 28KB
bootstrap.min.js 28KB
jqplot.mekkoAxisRenderer.js 25KB
jqplot.canvasTextRenderer.js 24KB
jqplot.pyramidGridRenderer.js 22KB
共 482 条
- 1
- 2
- 3
- 4
- 5
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6651
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功