mongo状态

pull/517/head
Mr Chen 1 year ago
parent 8976e97ea5
commit 502893194e
  1. 6
      plugins/mongodb/index.html
  2. 47
      plugins/mongodb/index.py
  3. 32
      plugins/mongodb/js/mongodb.js

@ -5,19 +5,21 @@
<p onclick="pluginInitD('mongodb');">自启动</p> <p onclick="pluginInitD('mongodb');">自启动</p>
<p onclick="pluginConfig('mongodb');">配置修改</p> <p onclick="pluginConfig('mongodb');">配置修改</p>
<p onclick="mongoStatus();">负载状态</p> <p onclick="mongoStatus();">负载状态</p>
<p onclick="mongoDocStatus();">文档状态</p>
<p onclick="pluginLogs('mongodb','','run_log');">日志</p> <p onclick="pluginLogs('mongodb','','run_log');">日志</p>
</div> </div>
<div class="bt-w-con pd15"> <div class="bt-w-con pd15">
<div class="soft-man-con"></div> <div class="soft-man-con" style="height:455px;overflow: auto;"></div>
</div> </div>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
//mongodb start //mongodb start
resetPluginWinHeight(530);
var loading = layer.msg("资源加载中...", { icon: 16, time: 0, shade: 0.3 }); var loading = layer.msg("资源加载中...", { icon: 16, time: 0, shade: 0.3 });
$.getScript( "/plugins/file?name=mongodb&f=js/mongodb.js", function(){ $.getScript( "/plugins/file?name=mongodb&f=js/mongodb.js", function(){
layer.close(loading); layer.close(loading);
pluginService('mongodb') pluginService('mongodb');
}); });
//mongodb end //mongodb end
</script> </script>

@ -5,6 +5,8 @@ import io
import os import os
import time import time
import re import re
import json
import datetime
sys.path.append(os.getcwd() + "/class/core") sys.path.append(os.getcwd() + "/class/core")
import mw import mw
@ -168,6 +170,7 @@ def restart():
def runInfo(): def runInfo():
import pymongo import pymongo
port = getConfPort() port = getConfPort()
client = pymongo.MongoClient(host='127.0.0.1', port=int(port)) client = pymongo.MongoClient(host='127.0.0.1', port=int(port))
db = client.admin db = client.admin
@ -175,24 +178,40 @@ def runInfo():
listDbs = client.list_database_names() listDbs = client.list_database_names()
showDbList = []
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 = {}
result["host"] = serverStatus['host']
result["version"] = serverStatus['version'] result["version"] = serverStatus['version']
result["uptime"] = serverStatus['uptime'] result["uptime"] = serverStatus['uptime']
result['db_path'] = getServerDir() + "/data" result['db_path'] = getServerDir() + "/data"
result["connections"] = serverStatus['connections']['current'] result["connections"] = serverStatus['connections']['current']
if 'catalogStats' in serverStatus: result["collections"] = len(listDbs)
result["collections"] = serverStatus['catalogStats']['collections']
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})
if 'operationTime' in stats:
del stats['operationTime']
if '$clusterTime' in stats:
del stats['$clusterTime']
showDbList.append(stats)
result["dbs"] = showDbList result["dbs"] = showDbList
return mw.getJson(result) return mw.getJson(result)
@ -280,6 +299,8 @@ if __name__ == "__main__":
print(initdUinstall()) print(initdUinstall())
elif func == 'run_info': elif func == 'run_info':
print(runInfo()) print(runInfo())
elif func == 'run_doc_info':
print(runDocInfo())
elif func == 'conf': elif func == 'conf':
print(getConf()) print(getConf())
elif func == 'run_log': elif func == 'run_log':

@ -8,18 +8,40 @@ function mongoStatus() {
} }
var rdata = $.parseJSON(data.data); var rdata = $.parseJSON(data.data);
hit = (parseInt(rdata.keyspace_hits) / (parseInt(rdata.keyspace_hits) + parseInt(rdata.keyspace_misses)) * 100).toFixed(2); var con = '<div class="divtable">\
var Con = '<div class="divtable">\
<table class="table table-hover table-bordered" style="width: 490px;">\ <table class="table table-hover table-bordered" style="width: 490px;">\
<thead><th>字段</th><th></th><th></th></thead>\ <thead><th>字段</th><th></th><th></th></thead>\
<tbody>\ <tbody>\
<tr><th>host</th><td>' + rdata.host + '</td><td></td></tr>\
<tr><th>version</th><td>' + rdata.version + '</td><td></td></tr>\ <tr><th>version</th><td>' + rdata.version + '</td><td></td></tr>\
<tr><th>db_path</th><td>' + rdata.db_path + '</td><td></td></tr>\ <tr><th>db_path</th><td>' + rdata.db_path + '</td><td></td></tr>\
<tr><th>uptime</th><td>' + rdata.uptime + '</td><td></td></tr>\ <tr><th>uptime</th><td>' + rdata.uptime + '</td><td></td></tr>\
<tr><th>connections</th><td>' + rdata.connections + '</td><td></td></tr>\ <tr><th>connections</th><td>' + rdata.connections + '</td><td></td></tr>\
<tr><th>collections</th><td>' + rdata.collections + '</td><td></td></tr>\ <tr><th>collections</th><td>' + rdata.collections + '</td><td></td></tr>\
<tr><th>insert</th><td>' + rdata.pf['insert'] + '</td><td></td></tr>\
<tr><th>query</th><td>' + rdata.pf['query'] + '</td><td></td></tr>\
<tr><th>update</th><td>' + rdata.pf['update'] + '</td><td></td></tr>\
<tr><th>delete</th><td>' + rdata.pf['delete'] + '</td><td></td></tr>\
<tr><th>getmore</th><td>' + rdata.pf['getmore'] + '</td><td>getmore</td></tr>\
<tr><th>command</th><td>' + rdata.pf['command'] + '</td><td></td></tr>\
<tbody>\ <tbody>\
</table></div><hr/>'; </table></div>';
$(".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 = ''; var t = '';
for(var i=0; i<rdata.dbs.length;i++){ for(var i=0; i<rdata.dbs.length;i++){
@ -35,13 +57,13 @@ function mongoStatus() {
} }
// console.log(t); // console.log(t);
Con += '<div class="divtable">\ var con = '<div class="divtable">\
<table class="table table-hover table-bordered" style="width: 490px;">\ <table class="table table-hover table-bordered" style="width: 490px;">\
<thead><th>库名</th><th></th><th></th><th></th><th></th><th></th><th></th></thead>\ <thead><th>库名</th><th></th><th></th><th></th><th></th><th></th><th></th></thead>\
<tbody>'+t+'<tbody>\ <tbody>'+t+'<tbody>\
</table></div>'; </table></div>';
// console.log(rdata.dbs); // console.log(rdata.dbs);
$(".soft-man-con").html(Con); $(".soft-man-con").html(con);
},'json'); },'json');
} }
Loading…
Cancel
Save