Skip to content

Commit

Permalink
redis添加会话管理
Browse files Browse the repository at this point in the history
  • Loading branch information
feiazifeiazi committed Sep 19, 2024
1 parent 913d380 commit bc5e992
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 3 deletions.
3 changes: 1 addition & 2 deletions sql/db_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ def process(request):

query_engine = get_engine(instance=instance)
query_result = None
if instance.db_type == "mysql":
if instance.db_type in ["mysql", "redis"]:
query_result = query_engine.processlist(command_type)

elif instance.db_type == "mongo":
query_result = query_engine.current_op(command_type)
elif instance.db_type == "oracle":
Expand Down
15 changes: 15 additions & 0 deletions sql/engines/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@ def query_check(self, db_name=None, sql="", limit_num=0):
result["msg"] = "禁止执行该命令!"
return result

def processlist(self, command_type):
"""获取连接信息"""
sql = "client list"
result_set = ResultSet(full_sql=sql)
conn = self.get_connection(db_name=0)
clients = conn.client_list()
# 根据空闲时间排序
sort_by = "idle"
reverse = False
clients = sorted(
clients, key=lambda client: client.get(sort_by), reverse=reverse
)
result_set.rows = clients
return result_set

def query(self, db_name=None, sql="", limit_num=0, close_conn=True, **kwargs):
"""返回 ResultSet"""
result_set = ResultSet(full_sql=sql)
Expand Down
111 changes: 110 additions & 1 deletion sql/templates/dbdiagnostic.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<optgroup id="optgroup-mysql" label="MySQL"></optgroup>
<optgroup id="optgroup-mongo" label="MongoDB"></optgroup>
<optgroup id="optgroup-oracle" label="Oracle"></optgroup>
<optgroup id="optgroup-redis" label="Redis"></optgroup>
</select>
</div>
<div id="command-div" class="form-group">
Expand Down Expand Up @@ -326,6 +327,111 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
return html.join('');
}
]
,[
'redis',
["All","",""],
[{
title: '', // 用于多选框
field: 'checkbox',
checkbox: true
}, {
title: 'Id',
field: 'id',
sortable: true
}, {
title: '远程地址',
field: 'addr',
sortable: true
}, {
title: '本地地址',
field: 'laddr',
sortable: true
}, {
title: '客户端名称',
field: 'name',
sortable: true
}, {
title: '用户',
field: 'user',
sortable: true
},
{
title: '数据库',
field: 'db',
sortable: true
}, {
title: '连接耗时(秒)',
field: 'age',
sortable: true
}, {
title: '空闲时间(秒)',
field: 'idle',
sortable: true
}, {
title: '命令',
field: 'cmd',
sortable: true
}, {
title: '总内存',
field: 'tot-mem',
sortable: true
},{
title: '输出内存',
field: 'omem',
sortable: true
}, {
title: '标志',
field: 'flags',
sortable: true
},{
title: '文件描述符',
field: 'fd',
sortable: true
},{
title: '订阅数',
field: 'sub',
sortable: true
}, {
title: '模式订阅数',
field: 'psub',
sortable: true
}, {
title: 'MULTI 队列长度',
field: 'multi',
sortable: true
}, {
title: '查询缓冲区',
field: 'qbuf',
sortable: true
}, {
title: '查询缓冲区空闲',
field: 'qbuf-free',
sortable: true
}, {
title: '参数内存',
field: 'argv-mem',
sortable: true
}, {
title: '输出缓冲区长度',
field: 'obl',
sortable: true
}, {
title: '输出链长度',
field: 'oll',
sortable: true
}, {
title: '事件文件',
field: 'events',
sortable: true
}, {
title: '重定向',
field: 'redir',
sortable: true
}],
function (index, row) {
var html = [];
}
]
]


Expand Down Expand Up @@ -936,7 +1042,7 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
url: "/group/user_all_instances/",
dataType: "json",
data: {
db_type: ['mysql','mongo', 'oracle']
db_type: ['mysql','mongo', 'oracle','redis']
},
complete: function () {
//如果已选择instance_name进入页面自动填充并且重置激活id
Expand All @@ -955,6 +1061,7 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
$("#optgroup-mysql").empty();
$("#optgroup-mongo").empty();
$("#optgroup-oracle").empty();
$("#optgroup-redis").empty();
for (let i = 0; i < result.length; i++) {
let instance = "<option value=\"" + result[i]['instance_name'] + "\">" + result[i]['instance_name'] + "</option>";
// $("#instance_name").append(instance);
Expand All @@ -964,6 +1071,8 @@ <h4 class="modal-title text-danger">确定要终止所选会话吗?</h4>
$("#optgroup-mongo").append(instance);
} else if (result[i]['db_type'] === 'oracle') {
$("#optgroup-oracle").append(instance);
} else if (result[i]['db_type'] === 'redis') {
$("#optgroup-redis").append(instance);
}
}
$('#instance_name').selectpicker('render');
Expand Down

0 comments on commit bc5e992

Please sign in to comment.