1

从远程机器;如何使用 pymongo 的 mongostat 从 pymongo 获取 mongostats?我正在使用代表集。

c = Connection("50.xxx.xxx.xxx:27017",replicaSet='test')
rep_status = c.admin.command("replSetGetStatus")
mongostat = c.admin.command("mongostat")

pymongo.errors.OperationFailure: command SON([('mongostat', 1)]) failed: no such cmd: mongostat
4

2 回答 2

2

使用 serverStatus 命令:

http://docs.mongodb.org/manual/reference/server-status/

你可以从 pymongo 调用它c.admin.command("serverStatus")

mongostat 中的所有相同信息都出现在 serverStatus 的结果中(事实上,所有 mongostat 在幕后所做的都是运行 serverStatus 命令,并格式化/打印输出)。

于 2013-04-12T15:39:05.370 回答
1

查看stdlib中的子进程模块:

from subprocess import call
call(["ls", "-l"])

你需要打电话mongostat --host HOST --port PORT。要连接到副本集,您可以指定副本集种子名称和集合成员的种子列表,格式如下:

<replica_set_name>/<hostname1><:port>,<hostname2:<port>,...

于 2013-02-22T11:10:27.400 回答