查看MongoDB中Replica Set的狀態

來源:互聯網
上載者:User

查看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.95.216: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.95.218: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()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.