mirror of
https://github.com/midoks/mdserver-web.git
synced 2026-10-10 05:59:25 +08:00
update
This commit is contained in:
@@ -516,6 +516,54 @@ class nosqlMySQLCtr():
|
||||
"""
|
||||
)
|
||||
return mw.returnData(True, 'ok', data)
|
||||
|
||||
def getLockSql(self, args):
|
||||
sid = args['sid']
|
||||
my_instance = self.getInstanceBySid(sid).conn()
|
||||
if my_instance is False:
|
||||
return mw.returnData(False,'无法链接')
|
||||
|
||||
data = my_instance.query(
|
||||
"""
|
||||
SELECT
|
||||
a.trx_id AS trx_id,
|
||||
a.trx_state AS trx_state,
|
||||
a.trx_started AS trx_started,
|
||||
b.id AS processlist_id,
|
||||
b.info AS info,
|
||||
b.user AS user,
|
||||
b.host AS host,
|
||||
b.db AS db,
|
||||
b.command AS command,
|
||||
b.state AS state,
|
||||
CONCAT('KILL QUERY ', b.id) AS sql_kill_blocking_query
|
||||
FROM
|
||||
information_schema.INNODB_TRX a,
|
||||
information_schema.PROCESSLIST b
|
||||
WHERE
|
||||
a.trx_mysql_thread_id = b.id
|
||||
ORDER BY
|
||||
a.trx_started
|
||||
"""
|
||||
)
|
||||
|
||||
print(data)
|
||||
return mw.returnData(True, 'ok', data)
|
||||
|
||||
def getDeadlockInfo(self, args):
|
||||
sid = args['sid']
|
||||
my_instance = self.getInstanceBySid(sid).conn()
|
||||
if my_instance is False:
|
||||
return mw.returnData(False,'无法链接')
|
||||
|
||||
data = my_instance.find("SHOW ENGINE INNODB STATUS")
|
||||
if data is not None:
|
||||
innodb_status = data['Status']
|
||||
deadlock_info = re.search(r"LATEST DETECTED DEADLOCK.*?WE ROLL BACK TRANSACTION\s+\(\d+\)", innodb_status, re.DOTALL)
|
||||
if deadlock_info is None:
|
||||
return mw.returnData(True, 'ok', '无锁表')
|
||||
return mw.returnData(True, 'ok', deadlock_info.group(0))
|
||||
return mw.returnData(True, 'ok', '无锁表')
|
||||
# ---------------------------------- run ----------------------------------
|
||||
# 获取 mysql 列表
|
||||
def get_db_list(args):
|
||||
@@ -578,6 +626,16 @@ def get_fpk_info(args):
|
||||
t = nosqlMySQLCtr()
|
||||
return t.getFpkInfo(args)
|
||||
|
||||
# 查看当前锁阻塞的SQL
|
||||
def get_lock_sql(args):
|
||||
t = nosqlMySQLCtr()
|
||||
return t.getLockSql(args)
|
||||
|
||||
# 查看死锁信息
|
||||
def get_deadlock_info(args):
|
||||
t = nosqlMySQLCtr()
|
||||
return t.getDeadlockInfo(args)
|
||||
|
||||
|
||||
# 测试
|
||||
def test(args):
|
||||
|
||||
@@ -656,6 +656,76 @@ function mysqlCommonFuncFpkInfo(){
|
||||
});
|
||||
}
|
||||
|
||||
function mysqlCommonFuncLockSQL(){
|
||||
function renderSQL(){
|
||||
var sid = mysqlGetSid();
|
||||
myPostCBN('get_lock_sql',{'sid':sid} ,function(rdata){
|
||||
var data = rdata.data;
|
||||
if (data['status']){
|
||||
var items = data.data;
|
||||
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 += '</tr>';
|
||||
tbody += t;
|
||||
}
|
||||
$('#mysql_data_id tbody').html(tbody);
|
||||
} else {
|
||||
layer.msg(data.msg,{icon:2});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: "查看当前锁阻塞的SQL",
|
||||
area: ['800px', '400px'],
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="bt-form pd20 divtable taskdivtable">\
|
||||
<table class="table table-hover" id="mysql_data_id">\
|
||||
<thead>\
|
||||
<th style="width:100px;">库名</th>\
|
||||
<th style="width:50px;">表名</th>\
|
||||
</thead>\
|
||||
<tbody></tbody>\
|
||||
</table>\
|
||||
</div>',
|
||||
success:function(i,l){
|
||||
renderSQL();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mysqlCommonFuncDeadlockInfo(){
|
||||
|
||||
function renderSQL(){
|
||||
var sid = mysqlGetSid();
|
||||
myPostCBN('get_deadlock_info',{'sid':sid} ,function(rdata){
|
||||
var data = rdata.data;
|
||||
$('#info_log').html(data.data);
|
||||
var ob = document.getElementById('info_log');
|
||||
ob.scrollTop = ob.scrollHeight;
|
||||
});
|
||||
}
|
||||
|
||||
layer.open({
|
||||
type: 1,
|
||||
title: "查看死锁信息",
|
||||
area: ['800px', '400px'],
|
||||
closeBtn: 1,
|
||||
shadeClose: false,
|
||||
content: '<div class="bt-form pd15">\
|
||||
<textarea readonly="" style="margin: 0px;height: 330px;width: 100%;background-color: #333;color:#fff; padding:0 5px" id="info_log"></textarea>\
|
||||
</div>',
|
||||
success:function(i,l){
|
||||
renderSQL();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function mysqlCommonFunc(){
|
||||
$('#mysql_common').unbind('click').click(function(){
|
||||
layer.open({
|
||||
@@ -671,6 +741,8 @@ function mysqlCommonFunc(){
|
||||
<button style="margin-bottom: 8px;" id="mysql_table_info" type="button" class="btn btn-default btn-sm">统计库里每个表的大小</button>\
|
||||
<button style="margin-bottom: 8px;" id="mysql_conn_count" type="button" class="btn btn-default btn-sm">查看应用端IP连接数总和</button>\
|
||||
<button style="margin-bottom: 8px;" id="mysql_fpk_info" type="button" class="btn btn-default btn-sm">快速找出没有主键的表</button>\
|
||||
<button style="margin-bottom: 8px;" id="mysql_lock_sql" type="button" class="btn btn-default btn-sm">查看当前锁阻塞的SQL</button>\
|
||||
<button style="margin-bottom: 8px;" id="mysql_deadlock_info" type="button" class="btn btn-default btn-sm">查看死锁信息</button>\
|
||||
</div>',
|
||||
success:function(i,l){
|
||||
$('#mysql_top_nsql').click(function(){
|
||||
@@ -696,6 +768,14 @@ function mysqlCommonFunc(){
|
||||
$('#mysql_fpk_info').click(function(){
|
||||
mysqlCommonFuncFpkInfo();
|
||||
});
|
||||
|
||||
$('#mysql_lock_sql').click(function(){
|
||||
mysqlCommonFuncLockSQL();
|
||||
});
|
||||
|
||||
$('#mysql_deadlock_info').click(function(){
|
||||
mysqlCommonFuncDeadlockInfo();
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user