Tampa
Tampa

Reputation: 78304

Getting mongostats from pymongo

From a remote machine; how can I use mongostat from pymongo to get mongostats from pymongo? I am usinng rep sets.

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

Upvotes: 1

Views: 1143

Answers (2)

mpobrien
mpobrien

Reputation: 4962

Use the serverStatus command:

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

You can call it from pymongo like c.admin.command("serverStatus")

All the same information that's in mongostat is present in the results of serverStatus (in fact, all mongostat is doing behind the scenes is running the serverStatus command, and formatting/printing the output).

Upvotes: 2

Nick
Nick

Reputation: 1554

Look at the subprocess module in the stdlib:

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

You'll need to call mongostat --host HOST --port PORT . To connect to a replica set, you can specify the replica set seed name, and a seed list of set members, in the following format:

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

Upvotes: 1

Related Questions