问题
I configured 3 machines with MongoDB ReplicaSet, and all is working great, I can connect to them, one of them dies and the remaining keep working, it is fine.
I connect with the URI: hostname1,hostname2,hostname3/?readPreference=secondary
, then I make some queries and they are working as well, but I want to check if this connection is really querying from the secondary node.
How can I check this? Should I just trust that this is being done this way?, I also was checking the logs on the machines with mongo, and all of them, show the same things, that the connection was made to all three (connection accepted from REMOTEIP #NUMBER).
I also made a quick test with Java, and reading the db.getReadPreference()
from the com.mongo.DB
I configured, and it is showing secondary. So it is the same, should I then trust this? is it correctly querying only the secondary node?
Thank you.
回答1:
1) use mongostat command, which will tell you how many different operations ( query, insert, update, delete, command, etc ) are coming to the server You will find that primary is not getting any 'query' operation but secondaries will.
mongostat -u<user-name> -p<password>
2) Use mongosniff, to know the queries coming to the server
回答2:
You can use mongotop syntax: mongotop -h ip:port seconds // seconds: int value to refesh the dashboard ex: mongotop -h 127.0.0.1:27017 5
来源:https://stackoverflow.com/questions/16921533/mongodb-how-to-check-which-node-i-connected-on-replicaset