diff --git a/plugins/mongodb/index.html b/plugins/mongodb/index.html index dcb713bef..2eebee2eb 100755 --- a/plugins/mongodb/index.html +++ b/plugins/mongodb/index.html @@ -5,19 +5,21 @@

自启动

配置修改

负载状态

+

文档状态

日志

-
+
\ No newline at end of file diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 8ef7a3470..7d7fc3282 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -5,6 +5,8 @@ import io import os import time import re +import json +import datetime sys.path.append(os.getcwd() + "/class/core") import mw @@ -168,31 +170,48 @@ def restart(): def runInfo(): import pymongo + port = getConfPort() client = pymongo.MongoClient(host='127.0.0.1', port=int(port)) db = client.admin serverStatus = db.command('serverStatus') listDbs = client.list_database_names() + + result = {} + result["host"] = serverStatus['host'] + result["version"] = serverStatus['version'] + result["uptime"] = serverStatus['uptime'] + result['db_path'] = getServerDir() + "/data" + result["connections"] = serverStatus['connections']['current'] + result["collections"] = len(listDbs) + + pf = serverStatus['opcounters'] + result['pf'] = pf + + return mw.getJson(result) + + +def runDocInfo(): + import pymongo + + port = getConfPort() + client = pymongo.MongoClient(host='127.0.0.1', port=int(port)) + db = client.admin + serverStatus = db.command('serverStatus') + listDbs = client.list_database_names() showDbList = [] + result = {} for x in range(len(listDbs)): mongd = client[listDbs[x]] stats = mongd.command({"dbstats": 1}) - showDbList.append(stats) - # print(showDbList) - # print(serverStatus) - # for key, value in serverStatus.items(): - # print(key, value) - result = {} - result["version"] = serverStatus['version'] - result["uptime"] = serverStatus['uptime'] - - result['db_path'] = getServerDir() + "/data" + if 'operationTime' in stats: + del stats['operationTime'] - result["connections"] = serverStatus['connections']['current'] - if 'catalogStats' in serverStatus: - result["collections"] = serverStatus['catalogStats']['collections'] + if '$clusterTime' in stats: + del stats['$clusterTime'] + showDbList.append(stats) result["dbs"] = showDbList return mw.getJson(result) @@ -280,6 +299,8 @@ if __name__ == "__main__": print(initdUinstall()) elif func == 'run_info': print(runInfo()) + elif func == 'run_doc_info': + print(runDocInfo()) elif func == 'conf': print(getConf()) elif func == 'run_log': diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index bff45b955..abb56bf95 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -8,18 +8,40 @@ function mongoStatus() { } var rdata = $.parseJSON(data.data); - hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2); - var Con = '
\ + var con = '
\ \ \ \ + \ \ \ \ \ \ + \ + \ + \ + \ + \ + \ \ -
字段当前值说明
host' + rdata.host + '服务器
version' + rdata.version + '版本
db_path' + rdata.db_path + '数据路径
uptime' + rdata.uptime + '已运行秒
connections' + rdata.connections + '当前链接数
collections' + rdata.collections + '文档数
insert' + rdata.pf['insert'] + '插入命令数
query' + rdata.pf['query'] + '查询命令数
update' + rdata.pf['update'] + '更新命令数
delete' + rdata.pf['delete'] + '删除命令数
getmore' + rdata.pf['getmore'] + 'getmore命令数
command' + rdata.pf['command'] + '执行命令数

'; +
'; + + $(".soft-man-con").html(con); + },'json'); +} + + +function mongoDocStatus() { + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + $.post('/plugins/run', {name:'mongodb', func:'run_doc_info'}, function(data) { + layer.close(loadT); + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + var rdata = $.parseJSON(data.data); var t = ''; for(var i=0; i\ \ \ '+t+'\
库名大小存储大小数据索引文档数据对象
'; // console.log(rdata.dbs); - $(".soft-man-con").html(Con); + $(".soft-man-con").html(con); },'json'); } \ No newline at end of file