查看Replica Set的状态,执行rs.status()即可

rs.status()
{
        "set" : "set1",
        "date" : "Thu Oct 28 2010 10:09:28 GMT+0800 (CST)",
        "myState" : 2,
        "members" : [
                {
                        "_id" : 0,
                        "name" : "192.168.x.x:10000",
                        "health" : 1,
                        "state" : 1,
                        "uptime" : 2486042,
                        "lastHeartbeat" : "Thu Oct 28 2010 10:09:26 GMT+0800 (CST)"
                },
                {
                        "_id" : 1,
                        "name" : "zjm-hadoop-slave217:10000",
                        "health" : 1,
                        "state" : 2,
                        "self" : true
                },
                {
                        "_id" : 2,
                        "name" : "192.168.x.x:10001",
                        "health" : 1,
                        "state" : 7,
                        "uptime" : 2486042,
                        "lastHeartbeat" : "Thu Oct 28 2010 10:09:27 GMT+0800 (CST)"
                }
        ],
        "ok" : 1
}

其中,health为1表明服务器正常,0表明服务器down了

state为1表明是Primary,2表明是Secondary,3是Recovering,7是Arbiter,8是Down

如果想在Secondary上find数据,需要先执行以下命令:

db.getMongo().setSlaveOk();
db.suv.find().count()

要查看某个Collection的信息,可以用db.suv.stats()

{
        "ns" : "suv.suv",
        "count" : 9519581,
        "size" : 573341552,
        "avgObjSize" : 60.2276037149114,
        "storageSize" : 736285696,
        "numExtents" : 21,
        "nindexes" : 3,
        "lastExtentSize" : 129238272,
        "paddingFactor" : 1,
        "flags" : 1,
        "totalIndexSize" : 1612344128,
        "indexSizes" : {
                "_id_" : 462365632,
                "Lt_1" : 790758336,
                "Cl.Cid_1" : 359220160
        },
        "ok" : 1
}

其中:

  1. size即为DataSize,是数据所占的空间大小
  2. storageSize为includes free space allocated to this collection,就是说包括已经分配但还空闲的空间
  3. totalIndexSize为所有索引所占的空间
  4. totalSize为该Collection所占的总空间,它等于storageSize+totalIndexSize

以上几个信息,也可以通过下面命令来查询:

db.suv.dataSize()
db.suv.storageSize()
db.suv.totalIndexSize()
db.suv.totalSize()