pull/632/head
Mr Chen 5 months ago
parent a8019d1ec4
commit bdd0634f61
  1. 45
      plugins/data_query/sql_mysql.py
  2. 59
      plugins/data_query/static/js/app.js

@ -546,10 +546,33 @@ class nosqlMySQLCtr():
a.trx_started
"""
)
print(data)
return mw.returnData(True, 'ok', data)
def killLockPid(self, args):
sid = args['sid']
my_instance = self.getInstanceBySid(sid).conn()
if my_instance is False:
return mw.returnData(False,'无法链接')
pid = args['pid']
my_instance.execute('kill %s' % pid)
return mw.returnData(True, '执行成功!')
def killAllLock(self, args):
sid = args['sid']
my_instance = self.getInstanceBySid(sid).conn()
if my_instance is False:
return mw.returnData(False,'无法链接')
data = self.getLockSql(args)
if data['status']:
pid_data = data['data']
for x in pid_data:
my_instance.execute('kill %s' % x['processlist_id'])
return mw.returnData(True, '执行成功!')
def getDeadlockInfo(self, args):
sid = args['sid']
my_instance = self.getInstanceBySid(sid).conn()
@ -589,9 +612,7 @@ class nosqlMySQLCtr():
else:
msg = '主从复制报错,请检查\nSlave_IO_Running状态值是:%s, | Slave_SQL_Running状态值是:%s\nLast_Error错误信息是:%s\nLast_SQL_Error错误信息是:%s\n' \
% (slave_info['Slave_IO_Running'], slave_info['Slave_SQL_Running'], slave_info['Last_Error'], slave_info['Last_SQL_Error'])
error_dict = my_instance.find('select LAST_ERROR_NUMBER,LAST_ERROR_MESSAGE,LAST_ERROR_TIMESTAMP '
'from performance_schema.replication_applier_status_by_worker '
'ORDER BY LAST_ERROR_TIMESTAMP desc limit 1')
error_dict = my_instance.find('select LAST_ERROR_NUMBER,LAST_ERROR_MESSAGE,LAST_ERROR_TIMESTAMP from performance_schema.replication_applier_status_by_worker ORDER BY LAST_ERROR_TIMESTAMP desc limit 1')
msg += '错误号是:%s \n' % error_dict['LAST_ERROR_NUMBER']
msg += '错误信息是:%s \n' % error_dict['LAST_ERROR_MESSAGE']
msg += '报错时间是:%s \n' % error_dict['LAST_ERROR_TIMESTAMP']
@ -665,6 +686,16 @@ def get_lock_sql(args):
t = nosqlMySQLCtr()
return t.getLockSql(args)
# KILL阻塞SQL
def kill_lock_pid(args):
t = nosqlMySQLCtr()
return t.killLockPid(args)
# KILL阻塞SQL
def kill_all_lock(args):
t = nosqlMySQLCtr()
return t.killAllLock(args)
# 查看死锁信息
def get_deadlock_info(args):
t = nosqlMySQLCtr()
@ -676,6 +707,10 @@ def get_slave_status(args):
return t.getSlaveStatus(args)
# 测试
def test(args):
sid = args['sid']

@ -666,12 +666,35 @@ function mysqlCommonFuncLockSQL(){
var tbody = '';
for (var i = 0; i < items.length; i++) {
var t = '<tr>';
t += '<td>'+items[i]['table_schema']+'</td>';
t += '<td>'+items[i]['table_name']+'</td>';
t += '<td>'+items[i]['trx_id']+'</td>';
t += '<td>'+items[i]['trx_state']+'</td>';
t += '<td>'+items[i]['trx_started']+'</td>';
t += '<td>'+items[i]['processlist_id']+'</td>';
t += '<td>'+items[i]['info']+'</td>';
t += '<td>'+items[i]['user']+'</td>';
t += '<td>'+items[i]['host']+'</td>';
t += '<td>'+items[i]['db']+'</td>';
t += '<td>'+items[i]['command']+'</td>';
t += '<td>'+items[i]['state']+'</td>';
t += '<td>'+items[i]['sql_kill_blocking_query']+'</td>';
t += '<td><a class="exec btlink" index="'+i+'">执行</a></td>';
t += '</tr>';
tbody += t;
}
$('#mysql_data_id tbody').html(tbody);
$('#mysql_data_id tbody .exec').click(function(){
var index = $(this).attr('index');
var pid = items[index]['processlist_id'];
myPostCB('kill_lock_pid', {'sid':sid, 'pid':pid}, function(rdata){
var data = rdata.data;
showMsg(data.msg,function(){
if (data.status){
renderSQL();
}
},{icon: data.status ? 1 : 2}, 2000);
});
});
} else {
layer.msg(data.msg,{icon:2});
}
@ -681,20 +704,46 @@ function mysqlCommonFuncLockSQL(){
layer.open({
type: 1,
title: "查看当前锁阻塞的SQL",
area: ['800px', '400px'],
area: ['1000px', '400px'],
closeBtn: 1,
shadeClose: false,
content: '<div class="bt-form pd20 divtable taskdivtable">\
<div class="mr20 pull-left" style="border-right: 1px solid #ccc; padding-right: 20px;">\
<button id="kill_all" type="button" class="btn btn-default btn-sm">关闭所有阻塞</button>\
</div>\
<hr />\
<table class="table table-hover" id="mysql_data_id">\
<thead>\
<th style="width:100px;">库名</th>\
<th style="width:50px;">表名</th>\
<th style="width:80px;">事务ID</th>\
<th style="width:80px;">事务状态</th>\
<th style="width:220px;">执行时间</th>\
<th style="width:100px;">线程ID</th>\
<th style="width:50px;">Info</th>\
<th style="width:50px;">user</th>\
<th style="width:50px;">host</th>\
<th style="width:50px;">db</th>\
<th style="width:50px;">command</th>\
<th style="width:50px;">state</th>\
<th style="width:140px;">kill</th>\
<th style="width:50px;">操作</th>\
</thead>\
<tbody></tbody>\
</table>\
</div>',
success:function(i,l){
renderSQL();
$('#kill_all').unbind('click').click(function(){
var sid = mysqlGetSid();
myPostCB('kill_all_lock', {'sid':sid}, function(rdata){
var data = rdata.data;
showMsg(data.msg,function(){
if (data.status){
renderSQL();
}
},{icon: data.status ? 1 : 2}, 2000);
});
});
}
});
}

Loading…
Cancel
Save