第四部分 效能篇 第十一章 MongoDB 效能監控

來源:互聯網
上載者:User

標籤:mongodb效能監控

聲明:該文章主要來自《MongoDB實戰》一書內容,主要想通過該書學習MongoDB的相應知識,加深理解,故寫在自己的博文當中,作為記錄在最後的章節中,會有一個自己集合MongoDB資料庫應用的JavaEE的web應用。

1、MongoStat

此工具可以快速的查看某組運行中的MongoDB執行個體的統計資訊,用法如下:

[[email protected] bin]# ./mongostat connected to: 127.0.0.1insert  query update delete getmore command flushes mapped  vsize    res faults     locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn       time     *0     *0     *0     *0       0     1|0       0   320m   939m    37m      1 zhangsan:0.1%          0       0|0     0|0    62b     3k     2   21:49:23     *0     *0     *0     *0       0     1|0       0   320m   939m    37m      0 zhangsan:0.0%          0       0|0     0|0    62b     3k     2   21:49:24     *0     *0     *0     *0       0     1|0       0   320m   939m    37m      0 zhangsan:0.0%          0       0|0     0|0    62b     3k     2   21:49:25     *0     *0     *0     *0       0     1|0       0   320m   939m    37m      0 zhangsan:0.0%          0       0|0     0|0    62b     3k     2   21:49:26 
欄位說明:

  • insert每秒插入量
  • query每秒查詢量
  • update每秒更新量
  • delete每秒刪除量
  • locked鎖定量
  • qr|qw用戶端查詢排隊長度(讀|寫)
  • ar|aw活躍用戶端量(讀|寫)
  • conn串連數
  • time目前時間
它每秒中重新整理一次狀態值,提供良好的可讀性,通過這些參數可以觀察到一個整體的效能情況。
2、db.serverStatus這個命令是最常用也是最基礎的查看執行個體運行狀態的命令之一,下面我們看一下它的輸出:
> db.serverStatus(){        "host" : "localhost.localdomain",        "version" : "2.6.6", --伺服器版本        "process" : "mongod",        "pid" : NumberLong(29293),        "uptime" : 23180,--啟動時間(秒)        "uptimeMillis" : NumberLong(23179942),        "uptimeEstimate" : 21041,        "localTime" : ISODate("2015-01-04T13:53:03.792Z"),        "asserts" : {                "regular" : 0,                "warning" : 0,                "msg" : 0,                "user" : 0,                "rollovers" : 0        },        "backgroundFlushing" : {                "flushes" : 386,                "total_ms" : 99,                "average_ms" : 0.25647668393782386,                "last_ms" : 0,                "last_finished" : ISODate("2015-01-04T13:52:44.259Z")        },        "connections" : {                "current" : 2,--當前活動串連量                "available" : 817,--剩餘空閑串連量                "totalCreated" : NumberLong(19)        },        "cursors" : {                "note" : "deprecated, use server status metrics",                "clientCursors_size" : 0,                "totalOpen" : 0,                "pinned" : 0,                "totalNoTimeout" : 0,                "timedOut" : 0        },        "dur" : {                "commits" : 29,                "journaledMB" : 0,                "writeToDataFilesMB" : 0,                "compression" : 0,                "commitsInWriteLock" : 0,                "earlyCommits" : 0,                "timeMs" : {                        "dt" : 3038,                        "prepLogBuffer" : 0,                        "writeToJournal" : 0,                        "writeToDataFiles" : 0,                        "remapPrivateView" : 0                }        },        "extra_info" : {                "note" : "fields vary by platform",                "heap_usage_bytes" : 62803792,                "page_faults" : 36        },        "globalLock" : {                "totalTime" : NumberLong("23179943000"),                "lockTime" : NumberLong(3334379),                "currentQueue" : {                        "total" : 0,--當前全部隊列量                        "readers" : 0,--讀請求隊列量                        "writers" : 0--寫請求隊列量                },                "activeClients" : {                        "total" : 0,--當前全部用戶端串連量                        "readers" : 0,--用戶端讀請求量                        "writers" : 0--用戶端寫請求量                }        },        "indexCounters" : {                "accesses" : 38,--索引被訪問量                "hits" : 38,--索引命中量                "misses" : 0,--索引偏差兩                "resets" : 0,                "missRatio" : 0--索引偏差率(未命中率)        },        "locks" : {                "." : {                        "timeLockedMicros" : {                                "R" : NumberLong(954466),                                "W" : NumberLong(3334379)                        },                        "timeAcquiringMicros" : {                                "R" : NumberLong(5652043),                                "W" : NumberLong(133798)                        }                },                "admin" : {                        "timeLockedMicros" : {                                "r" : NumberLong(255071),                                "w" : NumberLong(0)                        },                        "timeAcquiringMicros" : {                                "r" : NumberLong(67318),                                "w" : NumberLong(0)                        }                },                "local" : {                        "timeLockedMicros" : {                                "r" : NumberLong(82150),                                "w" : NumberLong(17)                        },                        "timeAcquiringMicros" : {                                "r" : NumberLong(18964),                                "w" : NumberLong(1)                        }                },                "zhangsan" : {                        "timeLockedMicros" : {                                "r" : NumberLong(8788),                                "w" : NumberLong(1673999)                        },                        "timeAcquiringMicros" : {                                "r" : NumberLong(1409),                                "w" : NumberLong(55)                        }                },                "temp" : {                        "timeLockedMicros" : {                                "r" : NumberLong(340424),                                "w" : NumberLong(2765621)                        },                        "timeAcquiringMicros" : {                                "r" : NumberLong(111659),                                "w" : NumberLong(6212)                        }                },                "test" : {                        "timeLockedMicros" : {                                "r" : NumberLong(602182),                                "w" : NumberLong(437948)                        },                        "timeAcquiringMicros" : {                                "r" : NumberLong(73084),                                "w" : NumberLong(85)                        }                }        },        "network" : {                "bytesIn" : 66494,--發給此伺服器的資料量(單位:byte)                "bytesOut" : 865147,--此伺服器發出的資料量(單位:byte)
                "numRequests" : 851--發給此伺服器的請求量        },        "opcounters" : {                "insert" : 9,--插入操作的量                "query" : 1928,--查詢操作的量                "update" : 8,--更新操作的量                "delete" : 2,                "getmore" : 0,                "command" : 812--其他動作的量        },        "opcountersRepl" : {                "insert" : 0,                "query" : 0,                "update" : 0,                "delete" : 0,                "getmore" : 0,                "command" : 0        },        "recordStats" : {                "accessesNotInMemory" : 0,                "pageFaultExceptionsThrown" : 0,                "admin" : {                        "accessesNotInMemory" : 0,                        "pageFaultExceptionsThrown" : 0                },                "local" : {                        "accessesNotInMemory" : 0,                        "pageFaultExceptionsThrown" : 0                },                "temp" : {                        "accessesNotInMemory" : 0,                        "pageFaultExceptionsThrown" : 0                },                "test" : {                        "accessesNotInMemory" : 0,                        "pageFaultExceptionsThrown" : 0                },                "zhangsan" : {                        "accessesNotInMemory" : 0,                        "pageFaultExceptionsThrown" : 0                }        },        "writeBacksQueued" : false,        "mem" : {                "bits" : 64,--64位系統                "resident" : 37,--佔用實體記憶體量                "virtual" : 939,--虛擬記憶體量                "supported" : true,--是否支援擴充記憶體                "mapped" : 320,                "mappedWithJournal" : 640        },        "metrics" : {                "cursor" : {                        "timedOut" : NumberLong(0),                        "open" : {                                "noTimeout" : NumberLong(0),                                "pinned" : NumberLong(0),                                "total" : NumberLong(0)                        }                },                "document" : {                        "deleted" : NumberLong(1),                        "inserted" : NumberLong(9),                        "returned" : NumberLong(428),                        "updated" : NumberLong(8)                },                "getLastError" : {                        "wtime" : {                                "num" : 0,                                "totalMillis" : 0                        },                        "wtimeouts" : NumberLong(0)                },                "operation" : {                        "fastmod" : NumberLong(1),                        "idhack" : NumberLong(0),                        "scanAndOrder" : NumberLong(0)                },                "queryExecutor" : {                        "scanned" : NumberLong(2),                        "scannedObjects" : NumberLong(2)                },                "record" : {                        "moves" : NumberLong(0)                },                "repl" : {                        "apply" : {                                "batches" : {                                        "num" : 0,                                        "totalMillis" : 0                                },                                "ops" : NumberLong(0)                        },                        "buffer" : {                                "count" : NumberLong(0),                                "maxSizeBytes" : 268435456,                                "sizeBytes" : NumberLong(0)                        },                        "network" : {                                "bytes" : NumberLong(0),                                "getmores" : {                                        "num" : 0,                                        "totalMillis" : 0                                },                                "ops" : NumberLong(0),                                "readersCreated" : NumberLong(0)                        },                        "preload" : {                                "docs" : {                                        "num" : 0,                                        "totalMillis" : 0                                },                                "indexes" : {                                        "num" : 0,                                        "totalMillis" : 0                                }                        }                },                "storage" : {                        "freelist" : {                                "search" : {                                        "bucketExhausted" : NumberLong(0),                                        "requests" : NumberLong(399),                                        "scanned" : NumberLong(731)                                }                        }                },                "ttl" : {                        "deletedDocuments" : NumberLong(0),                        "passes" : NumberLong(386)                }        },        "ok" : 1}> 

3、db.statsdb.stats查看資料庫狀態資訊,使用範例如下:
> db.stats(){        "db" : "test",        "collections" : 16,--collection數量        "objects" : 152,--對象數量        "avgObjSize" : 72.42105263157895,--對象平均大小        "dataSize" : 11008,--資料大小        "storageSize" : 131072,--資料大小(含預分配空間)        "numExtents" : 16,--事件數目量        "indexes" : 20,--索引數量        "indexSize" : 163520,--索引檔案大小        "fileSize" : 67108864,--檔案大小        "nsSizeMB" : 16,        "dataFileVersion" : {                "major" : 4,                "minor" : 5        },        "extentFreeList" : {                "num" : 1,                "totalSize" : 131072        },        "ok" : 1--本次取stats是否正常}> 
通過這個工具,可以查看當前資料庫的基本資料。

4、第三方工具

MongoDB從一面世就得到了眾多開源愛好者和團隊的重視,在常用的監控架構如cacti、Nagios、Zabbix等基礎上進行擴充,進行MongoDB的監控都是非常方便的。

---------------------------------MongoDB系列文章更新-----------------------------------------------------------------------------------------

第一部分 基礎篇 第一章 走進MongoDB

第一部分 基礎篇 第二章 安裝MongoDB

第一部分 基礎篇 第三章 MongoDB體繫結構

第一部分 基礎篇 第四章 MongoDB快速入門

第一部分 基礎篇 第四章 MongoDB查詢

第二部分 應用篇 第五章 MongoDB進階查詢

第二部分 應用篇 第六章 MongoDB GridFS

第二部分 應用篇 第七章 MongoDB MapReduce

第三部分 管理篇 第八章 MongoDB服務管理

第三部分 管理篇 第九章 MongoDB shell之系統命令、使用者命令

第三部分 管理篇 第九章 MongoDB shell之eval、進程

第四部分 效能篇 第十章 MongoDB 索引

第四部分 效能篇 第十一章 MongoDB 效能監控

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.