From 3fe4918b55f93fbc5ed16fb4dc562f5a6587ab32 Mon Sep 17 00:00:00 2001 From: Mr Chen Date: Mon, 22 Jan 2024 00:16:25 +0800 Subject: [PATCH] update --- plugins/mongodb/index.html | 11 +++++++ plugins/mongodb/index.py | 61 ++++++++++++++++++++++++++++++++++- plugins/mongodb/js/mongodb.js | 1 + 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/plugins/mongodb/index.html b/plugins/mongodb/index.html index 91d3755a8..68bd81ae6 100755 --- a/plugins/mongodb/index.html +++ b/plugins/mongodb/index.html @@ -1,3 +1,14 @@ + + +
diff --git a/plugins/mongodb/index.py b/plugins/mongodb/index.py index 0918bff0d..030bc16b1 100755 --- a/plugins/mongodb/index.py +++ b/plugins/mongodb/index.py @@ -78,7 +78,7 @@ def getArgs(): def status(): data = mw.execShell( - "ps -ef|grep mongod |grep -v grep | grep -v python | grep -v mdserver-web | awk '{print $2}'") + "ps -ef|grep mongod |grep -v grep | grep -v /Applications | grep -v python | grep -v mdserver-web | awk '{print $2}'") if data[0] == '': return 'stop' @@ -137,6 +137,7 @@ def mgOp(method): file = initDreplace() if mw.isAppleSystem(): data = mw.execShell(file + ' ' + method) + # print(data) if data[1] == '': return 'ok' return data[1] @@ -239,9 +240,65 @@ def runReplInfo(): result['setName'] = repl['setName'] result['primary'] = repl['primary'] result['me'] = repl['me'] + + hosts = repl['hosts'] + result['hosts'] = ','.join(hosts) + return mw.returnJson(True, 'OK', result) +def test(): + # https://pymongo.readthedocs.io/en/stable/examples/high_availability.html + import pymongo + from pymongo import ReadPreference + + port = getConfPort() + client = pymongo.MongoClient(host='127.0.0.1', port=int(port)) + db = client.admin + + # config = { + # '_id': 'test', + # 'members': [ + # {'_id': 1, 'host': '127.0.0.1:27018','priority': 10 }, + # {'_id': 2, 'host': '127.0.0.1:27019','priority': 1 }, + # {'_id': 3, 'host': '127.0.0.1:27020','priority': 0 }, + # # {'_id': 2, 'host': 'localhost:27019'} + # ] + # } + + # rsStatus = client.admin.command("replSetInitiate", config) + + + # -> rs.initiate({ + # _id: 'test', + # members: [{ + # _id: 1, + # host: '127.0.0.1:27018', + # priority: 2 // 这个priority不设置为1,值越高,当主库故障的时候会优先被选举成主库 + # }, { + # _id: 2, + # host: '127.0.0.1:27019', + # priority: 0 //设置为0则不能成为主库 + # }, { + # _id: 3, + # host: '127.0.0.1:27020', + # priority: 1 + # }] + # }); + + # > rs.status(); // 查询状态 + # // "stateStr" : "PRIMARY", 主节点 + # // "stateStr" : "SECONDARY", 副本节点 + + # > rs.add({"_id":3, "host":"127.0.0.1:27318","priority":0,"votes":0}); + + + serverStatus = db.command('serverStatus') + print(serverStatus) + + # return mw.returnJson(True, 'OK', result) + + def initdStatus(): if mw.isAppleSystem(): return "Apple Computer does not support" @@ -332,5 +389,7 @@ if __name__ == "__main__": print(getConf()) elif func == 'run_log': print(runLog()) + elif func == 'test': + print(test()) else: print('error') diff --git a/plugins/mongodb/js/mongodb.js b/plugins/mongodb/js/mongodb.js index 89f2d9f41..e3b5a783a 100644 --- a/plugins/mongodb/js/mongodb.js +++ b/plugins/mongodb/js/mongodb.js @@ -86,6 +86,7 @@ function mongoReplStatus() { } else{ tbody += '状态' + rdata.status + '主/从\ 同步文档' + rdata.setName + '文档名\ + hosts' + rdata.hosts + '服务器所有节点\ primary' + rdata.primary + 'primary\ me' + rdata.me + 'me'; }