mongodb 服务器性能监控,MongoDB监控
MongoDB監(jiān)控?
監(jiān)控是所有數(shù)據(jù)庫(kù)管理的重要組成部分。牢牢掌握 MongoDB 的報(bào)告將使您評(píng)估您的數(shù)據(jù)庫(kù)的狀態(tài),并使您的部署不出意外。另外, 一種MongoDB 的常規(guī)操作參數(shù)允許您在它們惡化為失敗之前進(jìn)行診斷。
本文概略地介紹了可用的監(jiān)控實(shí)用程序和在MongoDB中可用的統(tǒng)計(jì)報(bào)告。本文還介紹了監(jiān)控副本集和分片集群的診斷策略和建議。
注解
MongoDB Management Service (MMS) 是一項(xiàng)托管監(jiān)控服務(wù),該服務(wù)收集和聚合數(shù)據(jù)以供直觀地了解MongoDB部署的性能和操作。更多信息請(qǐng)參見(jiàn) MMS documentation 。
監(jiān)控策略?
有三種方法可用于收集正字運(yùn)行的 MongoDB 實(shí)例的狀態(tài)數(shù)據(jù):
第一種,有一套隨著MongoDB一起分發(fā)的實(shí)用程序提供了數(shù)據(jù)庫(kù)活動(dòng)的實(shí)時(shí)報(bào)告。
第二種, 數(shù)據(jù)庫(kù)命令 返回有關(guān)當(dāng)前數(shù)據(jù)庫(kù)狀態(tài)更高保真度的統(tǒng)計(jì)信息。
每個(gè)策略可以幫助解決不同的問(wèn)題,在不同的場(chǎng)景下各有其用。并且這些方法是相輔相成的。
MongoDB報(bào)表工具?
本節(jié)概述了隨MongoDB一起分發(fā)的報(bào)告方法。本節(jié)還提供了每一種方法最適合的那類問(wèn)題的例子來(lái)幫助您選擇合適的方法定位問(wèn)題。
實(shí)用程序?
MongoDB發(fā)行版包含了大量快速返回實(shí)例性能和活動(dòng)統(tǒng)計(jì)信息的實(shí)用程序。通常情況下,這些程序?qū)υ\斷問(wèn)題和評(píng)估一般操作是最有用。
mongostat?
mongostat 捕捉并返回各種類型(如插入、 查詢、 更新、 刪除等)數(shù)據(jù)庫(kù)操作的計(jì)數(shù)。這些計(jì)數(shù)展示了服務(wù)器上的負(fù)載分布。
使用 mongostat 以了解操作類型的分布,并告知容量規(guī)劃。詳細(xì)信息請(qǐng)參見(jiàn) mongostat 手冊(cè) 。
mongotop?
mongotop 追蹤并報(bào)告MongoDB實(shí)例當(dāng)前的讀取和寫入活動(dòng),而且是基于每個(gè)集合報(bào)告這些統(tǒng)計(jì)數(shù)據(jù)。
使用 mongotop 來(lái)檢查數(shù)據(jù)庫(kù)的活動(dòng)和使用是否符合您的期望。詳細(xì)信息請(qǐng)參見(jiàn) mongotop manual 。
HTTP 控制臺(tái)?
3.2 版后已移除:HTTP interface for MongoDB
MongoDB提供了一個(gè)在一個(gè)簡(jiǎn)單的網(wǎng)頁(yè)上展示診斷和監(jiān)控信息的網(wǎng)絡(luò)接口。該接口通過(guò)``localhost:``訪問(wèn), 其中的 比 mongod 的端口大 1000 。
例如,如果一個(gè)正在本地運(yùn)行的 mongod 使用默認(rèn)的端口 27017,那么在 http://localhost:28017 可以訪問(wèn)到HTTP控制臺(tái)。
命令?
MongoDB包含了許許多多報(bào)告數(shù)據(jù)庫(kù)狀態(tài)的命令。
這些數(shù)據(jù)可以比上文討論的實(shí)用程序提供更細(xì)層次的粒度。當(dāng)開(kāi)發(fā)自定義警報(bào),或改變您的應(yīng)用程序在響應(yīng)您的實(shí)例的活動(dòng)時(shí)的行為,請(qǐng)考慮在(您的)腳本和程序中使用其輸出。 db.currentOp 方法是另一種用于確定數(shù)據(jù)庫(kù)實(shí)例正在進(jìn)行的操作的有用工具,。
serverStatus?
serverStatus 命令,或外殼程序中的 db.serverStatus() 返回?cái)?shù)據(jù)庫(kù)狀態(tài)的總覽,具體包括磁盤使用狀況、 內(nèi)存使用狀況、 連接、 日志和可用的索引。此命令迅速返回,并不會(huì)影響 MongoDB 性能。
serverStatus 輸出MongoDB實(shí)例狀態(tài)的總覽。(然而我們)很少直接運(yùn)行該命令。(因?yàn)?在大多數(shù)情況下,人們通過(guò)監(jiān)控工具包括 MMS 看到的聚合過(guò)的數(shù)據(jù)才更有意義。盡管如此,所有管理員都應(yīng)熟悉 serverStatus 提供的數(shù)據(jù)。
dbStats?
dbStats 命令,或外殼程序中的 db.stats() 返回一份針對(duì)存儲(chǔ)使用情況和數(shù)據(jù)卷的文檔。 dbStats 顯示了存儲(chǔ)的使用量、包含在數(shù)據(jù)庫(kù)中的數(shù)據(jù)的總量以及對(duì)象、集合和索引計(jì)數(shù)器。
使用此數(shù)據(jù)來(lái)監(jiān)控特定數(shù)據(jù)庫(kù)的狀態(tài)和存儲(chǔ)容量。該輸出(的數(shù)據(jù))也可以讓你比較各數(shù)據(jù)庫(kù)的使用情況,并確定數(shù)據(jù)庫(kù)中 document 的平均大小。
collStats?
shell中的 collStats 或者 db.collection.stats() 在集合級(jí)別上提供類似 dbStats 的統(tǒng)計(jì)數(shù)據(jù),包括集合中對(duì)象的計(jì)數(shù)、集合的大小、集合占用的硬盤空間總量以及集合索引的相關(guān)信息。
replSetGetStatus?
replSetGetStatus 命令(對(duì)應(yīng)外殼程序中的 rs.status() )返回復(fù)制集狀態(tài)的總覽。 replSetGetStatus 文檔詳細(xì)描述了復(fù)制集的狀態(tài)和配置和有關(guān)復(fù)制集成員的統(tǒng)計(jì)信息。
參照此數(shù)據(jù)以確保復(fù)制集配置正確,并檢查當(dāng)前主機(jī)和其他副本集成員之間的連接。
第三方工具?
A number of third party monitoring tools have support for MongoDB,
either directly, or through their own plugins.
自托管的監(jiān)控工具?
以下這些是你必須在自己的服務(wù)器上安裝、配置、維護(hù)的監(jiān)控工具。(它們中的)大多數(shù)都是開(kāi)源的。
工具
插件
描述
報(bào)告內(nèi)存使用、btree統(tǒng)計(jì)情況、主/從狀態(tài)、當(dāng)前操作、每秒的操作的Python腳本。
None
MongoDB服務(wù)器的實(shí)時(shí)監(jiān)控工具。每秒以歷時(shí)長(zhǎng)短排序展示目前的操作。
None
和top類似的工具
Munin
Retrieves collection statistics (sizes, index sizes, and each
(configured) collection count for one DB).
Munin
一些不在主要發(fā)行版中的、附加的munin插件。
還可以考慮 dex,一個(gè)MongoDB的索引和查詢分析工具。該工具比較MongoDB的日志文件和索引并對(duì)索引提出建議。
Also consider dex, an index and
query analyzing tool for MongoDB that compares MongoDB log files and
indexes to make indexing recommendations.
參見(jiàn)
作為 MongoDB Enterprise 的一部分,你可以運(yùn)行 MMS On-Prem,它提供了在你的基礎(chǔ)設(shè)施上運(yùn)行MMS功能的包。
托管(SaaS)監(jiān)控工具?
以下這些是被作為托管服務(wù)提供的監(jiān)控工具,(它們)通常是通過(guò)付費(fèi)訂閱的。
名稱
說(shuō)明
MongoDB Cloud Manager is a cloud-based suite of services for managing MongoDB
deployments. MongoDB Cloud Manager provides monitoring, backup, and automation
functionality. For an on-premise solution, see also
Ops Manager, available in MongoDB Enterprise Advanced.
Dashboard for MongoDB,包含MongoDB特定的警報(bào),復(fù)制故障轉(zhuǎn)移的時(shí)間表以及iPhone、iPad、Android的移動(dòng)應(yīng)用程序。
IBM有一個(gè)應(yīng)用程序性能管理的SaaS產(chǎn)品,包括MongoDB的監(jiān)控器以及其他應(yīng)用程序和中間件。
New Relic offers full support for application performance
management. In addition, New Relic Plugins and Insights enable you to view
monitoring metrics from Cloud Manager in New Relic.
Infrastructure monitoring to visualize
the performance of your MongoDB deployments.
在(進(jìn)行)常規(guī)操作時(shí), mongod 和 mongos 實(shí)例會(huì)向標(biāo)準(zhǔn)輸出或日志文件寫入當(dāng)前帳號(hào)的所有服務(wù)器活動(dòng)和操作。以下的運(yùn)行時(shí)設(shè)置控制這些選項(xiàng)。
Process Logging?
During normal operation, mongod and mongos
instances report a live account of all server activity and operations
to either
standard output or a log file. The following runtime settings
control these options.
quiet. Limits the amount of information written to the
log or output.
verbosity. Increases the amount of information written to
the log or output. You can also modify the logging verbosity during
runtime with the logLevel parameter or the
db.setLogLevel() method in the shell.
path。開(kāi)啟記錄寫入到文件,而不是標(biāo)準(zhǔn)輸出。調(diào)整這個(gè)設(shè)置時(shí)必須指定完整的日志文件路徑。
logAppend。增加信息到一個(gè)日志文件而不是覆蓋原文件。
注解
你可以參照 mongod 或 mongos 的命令行參數(shù)指定這些配置操作。
例如:
mongod -v --logpath /var/log/mongodb/server1.log --logappend
以 verbose 模式啟動(dòng) mongod 實(shí)例,并向 /var/log/mongodb/server1.log/ 所在的日志文件追加數(shù)據(jù)。
Log Redaction?
3.4 新版功能:Available in MongoDB Enterprise only
A mongod running with security.redactClientLogData
redacts messages associated with any given
log event before logging, leaving only metadata, source files, or line numbers
related to the event. security.redactClientLogData prevents
potentially sensitive information from entering the system log at the cost of
diagnostic detail.
For example, the following operation inserts a document into a
mongod running without log redaction. The mongod
has systemLog.component.query.verbosity set to 0:
db.clients.insertOne( { "name" : Joe, "PII" : "Sensitive Information" } )
This operation produces the following log event:
2016-09-23T13:51:43.572-0400 I COMMAND [conn1] command employeeData.directory
appName: "MongoDB Shell"
command: insert {
insert: "directory",
documents: [
{
_id: ObjectId('57e56baf6a71e2b785153aec'),
name: "Joe",
PII: "Sensitive Information"
}
],
...
A mongod running with security.redactClientLogData
performing the same insert operation produces the following log event:
注解
The exact redacted output may change leading up to the MongoDB 3.4 release.
This output is based on the 3.3 development series build.
2016-09-23T13:51:43.572-0400 I COMMAND [conn1] ###
Use redactClientLogData in conjunction with
encryption to assist compliance with
regulatory requirements.
診斷性能問(wèn)題?
除非受制于系統(tǒng)范圍的約束,否則MongoDB對(duì)接入的連接沒(méi)有限制。你可以使用 ulimit 命令或通過(guò)修改系統(tǒng)的 /etc/sysctl 文件來(lái)修改系統(tǒng)的限制。更多詳情請(qǐng)參見(jiàn) UNIX系統(tǒng)下 ulimit 的設(shè)置 。
復(fù)制和監(jiān)控?
除了對(duì)任意MongoDB實(shí)例基本的監(jiān)控需求,對(duì)于復(fù)制集,管理員還必須監(jiān)控 復(fù)制延遲.”復(fù)制延遲” 指的是從一個(gè) primary 復(fù)制寫操作到 secondary 所花的總時(shí)間.一些小的延遲間隔是可以接受的,但兩個(gè)顯著的問(wèn)題會(huì)隨著復(fù)制延遲的增長(zhǎng)出現(xiàn):
第一個(gè),延遲期間發(fā)生的操作不會(huì)復(fù)制到一個(gè)或多個(gè)從節(jié)點(diǎn)。如果您使用復(fù)制以確保數(shù)據(jù)持久化,特別長(zhǎng)的延遲可能會(huì)影響到您的數(shù)據(jù)集的完整性。
第二個(gè),如果復(fù)制延遲超過(guò)操作日志(oplog) 的長(zhǎng)度,那么MongoDB就不得不在從節(jié)點(diǎn)上執(zhí)行一個(gè)初始化同步,即復(fù)制 primary 的所有數(shù)據(jù)并重建所有索引。這在正常情況下很少見(jiàn),但如果你設(shè)置的oplog比默認(rèn)值小,可能會(huì)出現(xiàn)該問(wèn)題。
注解
oplog的大小僅可在第一次運(yùn)行時(shí)通過(guò) mongod 命令的 --oplogSize 參數(shù)或最好使用MongoDB配置文件中的 oplogSizeMB 進(jìn)行配置.如果在運(yùn)行 --replSet 選項(xiàng)之前你沒(méi)有在命令行指定該參數(shù), mongod 將創(chuàng)建默認(rèn)大小的oplog.
默認(rèn)情況下,oplog(的大小)在64位系統(tǒng)上是總的可用磁盤空間的5%。有關(guān)更改oplog大小的詳細(xì)信息,請(qǐng)參閱 修改Oplog大小
復(fù)制問(wèn)題通常是成員之間網(wǎng)絡(luò)連接問(wèn)題或是 primary 沒(méi)有足夠的資源來(lái)支持應(yīng)用和復(fù)制的流量造成的結(jié)果。要檢查副本的狀態(tài),可以在命令行中使用 replSetGetStatus 或如下助手:
rs.status()
文檔 replSetGetStatus 提供了該輸出的更深入的總覽.一般情況下,查看 optimeDate 的值并特別留意 primary 和 secondary 成員們的時(shí)間差.
分片和監(jiān)控?
在大多數(shù)情況下, sharded clusters 的組件和所有其他的MongoDB實(shí)例同樣受益于監(jiān)測(cè)和分析。另外,集群需要更深入的監(jiān)測(cè)以確保數(shù)據(jù)被高效地分發(fā)在各節(jié)點(diǎn)之間,并且分片操作正確地發(fā)揮了作用。
參見(jiàn)
See the 分片 documentation for more
information.
配置服務(wù)器?
The config database maintains a map identifying which
documents are on which shards. The cluster updates this map as
chunks move between shards. When a configuration
server becomes inaccessible, certain sharding operations become
unavailable, such as moving chunks and starting mongos
instances. However, clusters remain accessible from already-running
mongos instances.
Because inaccessible configuration servers can seriously impact
the availability of a sharded cluster, you should monitor your
configuration servers to ensure that the cluster remains well
balanced and that mongos instances can restart.
MongoDB Cloud Manager and Ops Manager monitor config servers and can
create notifications if a config server becomes inaccessible. See the
MongoDB Cloud Manager documentation and Ops Manager documentation for more information.
均衡和數(shù)據(jù)塊分布?
最高效的 sharded cluster 部署能在分片間均勻地平衡 chunks .為了方便(達(dá)到)這一點(diǎn),MongoDB有個(gè)分配數(shù)據(jù)的后臺(tái) balancer 進(jìn)程以確保數(shù)據(jù)段總是最佳地分布 shards 間.
穩(wěn)定鎖?
幾乎所有情況下,當(dāng)平衡器變穩(wěn)定時(shí),他們使用過(guò)的所有鎖將自動(dòng)釋放。然而,由于任意一個(gè)持續(xù)時(shí)間過(guò)長(zhǎng)的鎖都可能阻止以后的平衡,所以確保所有鎖都是合法的非常重要。要檢查數(shù)據(jù)庫(kù)的鎖定狀態(tài),(你可以)用 mongo 命令行連接到一個(gè) mongos 實(shí)例。使用如下命令序列切換到 配置 數(shù)據(jù)庫(kù)并展示分片數(shù)據(jù)庫(kù)中所有的顯式鎖:
use config
db.locks.find()
對(duì)于正在活動(dòng)的部署,上面的查詢可以直觀的顯示.起源于隨機(jī)選擇的一個(gè) mongos 的平衡進(jìn)程使用了一種特殊的 “平衡器”–它可以阻止其他平衡活動(dòng)的擴(kuò)散.同樣地,對(duì) 配置 數(shù)據(jù)庫(kù)使用如下命令,即可檢查 “平衡器” 鎖的狀態(tài).
db.locks.find( { _id : "balancer" } )
在 3.4 版更改:Starting in 3.4, the primary of the CSRS config server holds the
“balancer” lock, using a process id named “ConfigServer”. This lock
is never released. To determine if the balancer is running, see
Check if Balancer is Running.
總結(jié)
以上是生活随笔為你收集整理的mongodb 服务器性能监控,MongoDB监控的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: STL--list的模拟实现
- 下一篇: 服务器项目描述,项目服务器 2010 S