diff --git a/sql/db_diagnostic.py b/sql/db_diagnostic.py index ca01b0bc96..683d266d27 100644 --- a/sql/db_diagnostic.py +++ b/sql/db_diagnostic.py @@ -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": diff --git a/sql/engines/redis.py b/sql/engines/redis.py index c22cf73b75..5e46c797b9 100644 --- a/sql/engines/redis.py +++ b/sql/engines/redis.py @@ -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) diff --git a/sql/templates/dbdiagnostic.html b/sql/templates/dbdiagnostic.html index eab4ee6933..3952cbf257 100644 --- a/sql/templates/dbdiagnostic.html +++ b/sql/templates/dbdiagnostic.html @@ -27,6 +27,7 @@ +
@@ -326,6 +327,111 @@ 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 = []; + } + ] ] @@ -936,7 +1042,7 @@ url: "/group/user_all_instances/", dataType: "json", data: { - db_type: ['mysql','mongo', 'oracle'] + db_type: ['mysql','mongo', 'oracle','redis'] }, complete: function () { //如果已选择instance_name,进入页面自动填充,并且重置激活id @@ -955,6 +1061,7 @@ $("#optgroup-mysql").empty(); $("#optgroup-mongo").empty(); $("#optgroup-oracle").empty(); + $("#optgroup-redis").empty(); for (let i = 0; i < result.length; i++) { let instance = ""; // $("#instance_name").append(instance); @@ -964,6 +1071,8 @@ $("#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');