糖醋排骨教主 發表於 2019-6-15 12:17:00

011.MongoDB性能监控

<h2 align="left">一 MongoDB 监控</h2>
<h3 align="left">1.1 监控概述</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">MongoDB自带了mongostat 和 mongotop 这两个命令来监控MongoDB的运行情况。这两个命令用于处理MongoDB数据库变慢等等问题非常有用,能详细的统计MongoDB当前的状态信息。除此之外,还可以用db.serverStatus()、db.stats()、开启profile功能通过查看日志进行监控分析。</span></div>
<h3 align="left">1.2 模拟插入数据</h3>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> # mongo --host 172.24.8.71 -u admin -p admin
<span style="color: rgba(0, 128, 128, 1)">2</span> &gt; use admin
<span style="color: rgba(0, 128, 128, 1)">3</span> &gt; db.grantRolesToUser( "admin",[{ role: "dbOwner",db:"mydb" }])
<span style="color: rgba(0, 128, 128, 1)">4</span> &gt; for(i=1;i<span style="color: rgba(0, 0, 255, 1)">&lt;</span>=50000;i++){db.user.insert({"id":i,"name":"jack"+i})}</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<h2 align="left">二 相关命令</h2>
<h3 align="left">2.1 mongostat 命令</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">mongostat是mongodb自带的状态检测工具,在命令行下使用。它会间隔固定时间获取mongodb的当前运行状态,并输出。捕捉并返回各种类型(如插入、 查询、 更新、 删除等)数据库操作的统计。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">相关输出解释:</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> inserts/s                #每秒插入次数
<span style="color: rgba(0, 128, 128, 1)">2</span> query/s                #每秒查询次数
<span style="color: rgba(0, 128, 128, 1)">3</span> update/s                #每秒更新次数
<span style="color: rgba(0, 128, 128, 1)">4</span> delete/s                #每秒删除次数
<span style="color: rgba(0, 128, 128, 1)">5</span> getmore/s                #每秒执行getmore次数
<span style="color: rgba(0, 128, 128, 1)">6</span> command/s                #每秒的命令数,比以上插入、查找、更新、删除的综合还多,还统计了别的命令
<span style="color: rgba(0, 128, 128, 1)">7</span> dirty                #仅仅针对WiredTiger引擎,脏数据字节的缓存百分比
<span style="color: rgba(0, 128, 128, 1)">8</span> used                #仅仅针对WiredTiger引擎,正在使用中的缓存百分比
<span style="color: rgba(0, 128, 128, 1)">9</span> flushs/s                #每秒执行fsync将数据写入硬盘的次数。</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>注意:flushs一般都是0,间断性会是1,通过计算两个1之间的间隔时间,可以大致了解多长时间flush一次。flush开销较大,如果频繁的flush,可能存在异常。</strong></span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> mapped/s                #所有的被mmap的数据量,单位是MB,
<span style="color: rgba(0, 128, 128, 1)">2</span> vsize                #虚拟内存使用量,单位MB
<span style="color: rgba(0, 128, 128, 1)">3</span> res                        #物理内存使用量,单位MB
<span style="color: rgba(0, 128, 128, 1)">4</span> faults/s                #每秒访问失败数(只有Linux有),数据被交换出物理内存,放到swap。不要超过100,否则就是机器内存太小,造成频繁swap写入。此时要升级内存或者扩展
<span style="color: rgba(0, 128, 128, 1)">5</span> locked %                #被锁的时间百分比,尽量控制在50%以下吧
<span style="color: rgba(0, 128, 128, 1)">6</span> idx miss %                #索引不命中所占百分比。如果太高的话就要考虑索引是不是少了
<span style="color: rgba(0, 128, 128, 1)">7</span> q t|r|w                #当Mongodb接收到太多的命令而数据库被锁住无法执行完成,它会将命令加入队列。这一栏显示了总共、读、写3个队列的长度,都为0的话表示mongo毫无压力。高并发时,一般队列值会升高。
<span style="color: rgba(0, 128, 128, 1)">8</span> qr                        #客户端等待从MongoDB实例读数据的队列长度
<span style="color: rgba(0, 128, 128, 1)">9</span> qw                        #客户端等待从MongoDB实例写入数据的队列长度
<span style="color: rgba(0, 128, 128, 1)"> 10</span> ar                        #执行读操作的活跃客户端数量
<span style="color: rgba(0, 128, 128, 1)"> 11</span> aw                        #执行写操作的活客户端数量</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>注意:如果这两个数值很大,即DB的处理速度不及请求速度。可能存在开销很大的慢查询。如果查询一切正常,确实是负载很大,可能是资源不够。</strong></span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> conn                        #当前连接数,是qr,qw,ar,aw的总和
<span style="color: rgba(0, 128, 128, 1)">2</span> time                        #时间戳
<span style="color: rgba(0, 128, 128, 1)">3</span> net_in                        #MongoDB实例的网络进流量
<span style="color: rgba(0, 128, 128, 1)">4</span> net_out                        #MongoDB实例的网络出流量</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>注意:MongoDB为每一个连接创建一个线程,线程的创建与释放也会有开销,所以尽量要适当配置连接数的启动参数,maxIncomingConnections建议在5000以下,基本满足多数场景。</strong></span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">示例:</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> # mongo --host 172.24.8.71 -u admin -p admin
<span style="color: rgba(0, 128, 128, 1)">2</span> &gt; use admin
<span style="color: rgba(0, 128, 128, 1)">3</span> &gt; db.grantRolesToUser( "admin",[{ role: "clusterMonitor",db:"admin" }])
<span style="color: rgba(0, 128, 128, 1)">4</span> # mongostat -h 172.24.8.71 -u admin -p admin --authenticationDatabase admin --discover -n 30 3</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">参数说明</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">-discover:提供集群中所有节点的状态;</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">-n 30 3:表示输出30次,每次休眠3秒钟。</span></div>
<div style="line-height: normal; float: none; -ms-word-break: normal" align="center"><img style="margin: 0 auto; border: 0 currentColor; border-image: none; float: none; display: block; background-image: none" title="031" src="https://img2018.cnblogs.com/blog/680719/201906/680719-20190615121720486-68104438.png" alt="031" width="1067" height="334" border="0"></div>
<h3 align="left">2.2 mongotop 命令</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">mongotop也是mongodb下的一个内置工具,mongotop提供了一个方法,用来跟踪一个MongoDB的实例,查看哪些大量的时间花费在读取和写入数据。 追踪并报告MongoDB实例当前的读取和写入活动,而且是基于每个集合报告这些统计数据。提供每个集合的水平的统计数据。默认情况下,mongotop返回值的每一秒。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">相关输出解释:</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> ns                                #数据库命名空间,后者结合了数据库名称和集合。
<span style="color: rgba(0, 128, 128, 1)">2</span> db                                #数据库的名称。名为 . 的数据库针对全局锁定,而非特定数据库。
<span style="color: rgba(0, 128, 128, 1)">3</span> total                        #mongod在这个命令空间上花费的总时间。
<span style="color: rgba(0, 128, 128, 1)">4</span> read                        #在这个命令空间上mongod执行读操作花费的时间。
<span style="color: rgba(0, 128, 128, 1)">5</span> write                        #在这个命名空间上mongod进行写操作花费的时间。</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">示例:</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> # mongotop -h 172.24.8.71 -u admin -p admin --authenticationDatabase admin -n 30 3</pre>
</div>
<div style="line-height: normal; float: none; -ms-word-break: normal" align="center"><img style="margin: 0 auto; border: 0 currentColor; border-image: none; float: none; display: block; background-image: none" title="032" src="https://img2018.cnblogs.com/blog/680719/201906/680719-20190615121721218-2077088893.png" alt="032" width="778" height="176" border="0"></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">参数说明</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> -n 30 3:表示输出30次,每次休眠3秒钟。</pre>
</div>
<h3 align="left">2.3 profile</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">mongodb慢查询检查,Profiler默认为关闭状态,可以选择全部开启,或者有慢查询的时候开启。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">相关输出解释:</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> ts                                #时间戳
<span style="color: rgba(0, 128, 128, 1)">2</span> info                        #具体的操作
<span style="color: rgba(0, 128, 128, 1)">3</span> millis                        #操作所花时间,毫秒
<span style="color: rgba(0, 128, 128, 1)">4</span> # mongo --host 172.24.8.71 -u admin -p admin
<span style="color: rgba(0, 128, 128, 1)">5</span> &gt; use mydb
<span style="color: rgba(0, 128, 128, 1)">6</span> &gt; db.setProfilingLevel(2)        #开启profile
<span style="color: rgba(0, 128, 128, 1)">7</span> { "was" : 2, "slowms" : 100, "sampleRate" : 1, "ok" : 1 }
<span style="color: rgba(0, 128, 128, 1)">8</span> &gt; db.getProfilingLevel()
<span style="color: rgba(0, 128, 128, 1)">9</span> 2
<span style="color: rgba(0, 128, 128, 1)"> 10</span> &gt; use mydb
<span style="color: rgba(0, 128, 128, 1)"> 11</span> switched to db mydb
<span style="color: rgba(0, 128, 128, 1)"> 12</span> &gt; db.system.profile.find().sort({$natural:-1}).pretty()        #查看Profile日志
<span style="color: rgba(0, 128, 128, 1)"> 13</span> &gt; db.system.profile.count()                                #查看系统中的慢查询数量
<span style="color: rgba(0, 128, 128, 1)"> 14</span> 6</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>注意:profile操作必须连接mongod进程,而mongos无法执行此类操作;</strong></span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>造成满查询可能是索引的问题,也可能是数据不在内存造成因此磁盘读入造成。</strong></span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>更多慢查询操作见官方文档:https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/</strong></span></div>
<h3 align="left">2.4 serverStatus</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">serverStatus命令,或mongo shell中的db.serverStatus()返回数据库状态的总览,具体包括磁盘使用状况、内存使用状况、连接、日志和可用的索引。此命令迅速返回,并不会影响MongoDB性能。</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> &gt; use mydb
<span style="color: rgba(0, 128, 128, 1)">2</span> &gt; db.serverStatus()                                        #只显示部分内容
<span style="color: rgba(0, 128, 128, 1)">3</span> {
<span style="color: rgba(0, 128, 128, 1)">4</span> "uptime" : 21.0,                                        #表示此实例进程已激活的总时间,单位是秒
<span style="color: rgba(0, 128, 128, 1)">5</span> "localTime" : ISODate("2017-07-09T05:28:17.007Z"),        #表示实例所在服务器的当前时间
<span style="color: rgba(0, 128, 128, 1)">6</span> "globalLock" : {
<span style="color: rgba(0, 128, 128, 1)">7</span>         "totalTime" : NumberLong(20935000),                #数据库启动后运行的总时间,单位是微秒
<span style="color: rgba(0, 128, 128, 1)">8</span>         "currentQueue" : {                                #表示因为锁引起读写队列数
<span style="color: rgba(0, 128, 128, 1)">9</span>             "total" : 0,
<span style="color: rgba(0, 128, 128, 1)"> 10</span>             "readers" : 0,                                #等待读锁的操作数
<span style="color: rgba(0, 128, 128, 1)"> 11</span>             "writers" : 0                                #等待写锁的操作数
<span style="color: rgba(0, 128, 128, 1)"> 12</span>         },
<span style="color: rgba(0, 128, 128, 1)"> 13</span>         "activeClients" : {                                #连接的激活客户端写操作的总数
<span style="color: rgba(0, 128, 128, 1)"> 14</span>             "total" : 10,
<span style="color: rgba(0, 128, 128, 1)"> 15</span>             "readers" : 0,                                #激活客户端读操作数
<span style="color: rgba(0, 128, 128, 1)"> 16</span>             "writers" : 0                                #激活客户端写操作数
<span style="color: rgba(0, 128, 128, 1)"> 17</span>         }
<span style="color: rgba(0, 128, 128, 1)"> 18</span>   },
<span style="color: rgba(0, 128, 128, 1)"> 19</span>   "mem" : {                                        #表示当前内存使用情况
<span style="color: rgba(0, 128, 128, 1)"> 20</span>         "bits" : 64,                                #mongod运行的目标机器的架构
<span style="color: rgba(0, 128, 128, 1)"> 21</span>         "resident" : 96,                                #当前被使用的物理内存总量,单位MB
<span style="color: rgba(0, 128, 128, 1)"> 22</span>         "virtual" : 271,                                #MongoDB进程映射的虚拟内存大小,单位MB
<span style="color: rgba(0, 128, 128, 1)"> 23</span>         "supported" : true,                                #表示系统是否支持可扩展内存
<span style="color: rgba(0, 128, 128, 1)"> 24</span>         "mapped" : 0,                                #映射数据文件所使用的内存大小,单位MB
<span style="color: rgba(0, 128, 128, 1)"> 25</span>         "mappedWithJournal" : 0                        #映射journaling所使用的内存大小,单位MB
<span style="color: rgba(0, 128, 128, 1)"> 26</span>   },
<span style="color: rgba(0, 128, 128, 1)"> 27</span> }</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">关键输出:</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">connections:当前连接和可用连接数,设个一个合理值,当到达这个值mongodb就拒绝新的连接请求,避免连接太多而影响性能。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">indexCounters:btree:misses 索引的不命中数,和hits的比例高就要考虑索引是否正确建立。</span></div>
<h3 align="left">2.5 db.stats()、db.c.stats()</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">MongoDB数据文件状态指标命令: db.stats(), db.c.stats(),查看文件大小,存储空间大小等。返回一份针对存储使用情况和数据卷的文档,dbStats显示了存储的使用量、包含在数据库中的数据的总量以及对象、集合和索引计数器。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">示例:</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> &gt; use mydb
<span style="color: rgba(0, 128, 128, 1)">2</span> &gt; db.stats()
<span style="color: rgba(0, 128, 128, 1)">3</span> {
<span style="color: rgba(0, 128, 128, 1)">4</span>         "db" : "mydb",                                #当前数据库
<span style="color: rgba(0, 128, 128, 1)">5</span>         "collections" : 2,                                #集合数量
<span style="color: rgba(0, 128, 128, 1)">6</span>         "views" : 0,
<span style="color: rgba(0, 128, 128, 1)">7</span>         "objects" : 50007,                                #对象(记录)数量
<span style="color: rgba(0, 128, 128, 1)">8</span>         "avgObjSize" : 53.88963545103685,                #对象平均大小
<span style="color: rgba(0, 128, 128, 1)">9</span>         "dataSize" : 2694859,                        #所有数据总大小
<span style="color: rgba(0, 128, 128, 1)"> 10</span>         "storageSize" : 917504,                        #数据占磁盘大小
<span style="color: rgba(0, 128, 128, 1)"> 11</span>         "numExtents" : 0,                                #所有集合占用的区间总数
<span style="color: rgba(0, 128, 128, 1)"> 12</span>         "indexes" : 1,                                #索引数
<span style="color: rgba(0, 128, 128, 1)"> 13</span>         "indexSize" : 491520,                        #索引大小
<span style="color: rgba(0, 128, 128, 1)"> 14</span>         "fsUsedSize" : 2733277184,
<span style="color: rgba(0, 128, 128, 1)"> 15</span>         "fsTotalSize" : 27375431680,
<span style="color: rgba(0, 128, 128, 1)"> 16</span>         "ok" : 1
<span style="color: rgba(0, 128, 128, 1)"> 17</span> }</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="color: rgba(255, 0, 0, 1); font-family: 微软雅黑; font-size: small"><strong>提示:MongoDB数据库磁盘占用大小=storageSize+indexes,压缩比=dataSize/storageSize。</strong></span></div>
<h3 align="left">2.6 db.collection.stats()</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">在集合级别上提供类似dbStats的统计数据,包括集合中对象的计数、集合的大小、集合占用的硬盘空间总量以及集合索引的相关信息。</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> &gt; use mydb
<span style="color: rgba(0, 128, 128, 1)">2</span> switched to db mydb
<span style="color: rgba(0, 128, 128, 1)">3</span> &gt; db.user.stats()</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<h3 align="left">2.7 db.currentOp()</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">通常Mongodb的命令一般很快就完成,但是在一台繁忙的机器或者有比较慢的命令时,可以通过db.currentOp()获取当前正在执行的操作。</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> &gt; db.currentOp()</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small"><span style="color: rgba(255, 0, 0, 1)"><strong>提示:若发现一个操作太长,导致数据库卡死,可以使用db.killOp("110752")杀死。</strong></span><span style="font-family: 微软雅黑; font-size: small"><span style="font-family: 微软雅黑; font-size: small"><br></span></span></span></div>
<h3 align="left">2.8        rs.status()</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">MongoDB副本集状态指标命令。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">相关输出解释:</span></div>
<div style="line-height: normal; overflow: auto; -ms-word-break: normal">
<table style="overflow: visible; display: table; white-space: nowrap; border-collapse: collapse; table-layout: fixed; max-width: none; border-spacing: 2px 2px"><colgroup><col width="188"><col width="275"></colgroup>
<tbody>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-0-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small"><strong>分段</strong></span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-0-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small"><strong>说明</strong></span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-1-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">set</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-1-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">当前副本集名称</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-2-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">date</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-2-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">执行命令时间</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-3-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">myState</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-3-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">当前节点的状态(角色)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-4-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">syncingTo</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-4-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">同步源</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-5-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">heartbeatIntervalMillis</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-5-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">心跳间隔</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-6-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-6-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">节点成员</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-7-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.id</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-7-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员编号</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-8-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.name</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-8-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员名称</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-9-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.heath</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-9-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">健康状态,1-true,0-false</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-10-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.state</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-10-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员状态(角色)1-主节点 2-备节点 7-仲裁节点</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-11-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.stateStr</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-11-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员状态名</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-12-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.uptime</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-12-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员启动运行时长</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-13-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.optime</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-13-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员oplog时间戳(字段ts)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-14-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.optimeDate</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-14-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员oplog时间(格式化)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-15-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.lastHeartbeat</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-15-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">当前节点对成员的最后一个心跳</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-16-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.lastHeartbeatRecv</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-16-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">当前节点收到该成员的最后一个心跳</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-17-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.pingMs</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-17-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">当前节点到该成员的回路时长</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-18-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.syncingTo</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-18-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">成员同步源</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-19-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.electionTime</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-19-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">主节点选举时间戳(ms)</span></div>
</td>
</tr>
<tr style="height: 40px">
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-20-0">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">members.electionDate</span></div>
</td>
<td style="padding: 1px; border: 1px solid rgba(167, 167, 167, 1); border-image: none; overflow: hidden; vertical-align: middle; white-space: pre-wrap; -ms-word-wrap: break-word" align="center" data-cell-id="3340-1559225114743-cell-20-1">
<div class="table-cell-line"><span style="font-family: 微软雅黑; font-size: small">主节点选举时间(格式化)</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="line-height: normal; -ms-word-break: normal"><ol style="margin: 0; padding-left: 30pt">
<li style="text-align: left; line-height: 1.75; list-style-type: decimal; list-style-position: inside; white-space: pre-wrap; background-color: rgba(0, 0, 0, 0)"><span style="font-family: 微软雅黑; font-size: small">检查每个成员的state/stateStr确认是否正常;</span></li>
</ol></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">提示:state状态字段解释可参考官方:https://docs.mongodb.com/manual/reference/replica-states/或https://yq.aliyun.com/articles/405274。</span></div>
<div style="line-height: normal; -ms-word-break: normal"><ol style="margin: 0; padding-left: 30pt" start="2">
<li style="text-align: left; line-height: 1.75; list-style-type: decimal; list-style-position: inside; white-space: pre-wrap; background-color: rgba(0, 0, 0, 0)"><span style="font-family: 微软雅黑; font-size: small">检查每个成员的optimeDate差异,查看复制延迟;</span></li>
<li style="text-align: left; line-height: 1.75; list-style-type: decimal; list-style-position: inside; white-space: pre-wrap; background-color: rgba(0, 0, 0, 0)"><span style="font-family: 微软雅黑; font-size: small">检查lastHeartbeat、pingMs值排查网络延迟问题</span></li>
</ol></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">使用db.printReplicationInfo()输出节点oplog信息,可在主备节点输出对比</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> configured oplog size:   20480MB
<span style="color: rgba(0, 128, 128, 1)">2</span> log length start to end: 589911secs (163.86hrs)
<span style="color: rgba(0, 128, 128, 1)">3</span> oplog first event time:Tue Apr 03 2018 19:37:14 GMT+0800
<span style="color: rgba(0, 128, 128, 1)">4</span> oplog last event time:   Tue Apr 10 2018 15:29:05 GMT+0800
<span style="color: rgba(0, 128, 128, 1)">5</span> now:                     Tue Apr 10 2018 15:30:18 GMT+0800</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">主节点使用db.printSlaveReplicationInfo()可输出备节点的同步信息</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> source: 135.177.126.24:10001
<span style="color: rgba(0, 128, 128, 1)">2</span>   syncedTo: Tue Apr 10 2018 15:32:45 GMT+0800
<span style="color: rgba(0, 128, 128, 1)">3</span>   0 secs (0 hrs) behind the primary</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<h2 align="left">三 motop监控工具</h2>
<h3 align="left">3.1 motop安装</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">motop是mongodb实时监控工具,可以同时对多个MongoDB服务器进行监控,同时显示当前操作。</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">语法格式:</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">motop [-h] [-u USERNAME] [-p PASSWORD] [-c CONF] [-V] [-K AUTOKILLSECONDS] ]</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">开源项目地址:项目地址:https://github.com/tart/motop</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> # yum -y install pymongo                                #安装以来
<span style="color: rgba(0, 128, 128, 1)">2</span> # curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
<span style="color: rgba(0, 128, 128, 1)">3</span> # python get-pip.py
<span style="color: rgba(0, 128, 128, 1)">4</span> # yum -y install git
<span style="color: rgba(0, 128, 128, 1)">5</span> # pip install git+https://github.com/tart/motop.git</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<h3 align="left">3.2 motop操作</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">q:退出</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">p:暂停</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">e:解释查询</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">k:使用“mongo”执行杀死操作</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">K:使用“mongo”执行杀死比给定秒数更早的操作</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">r:尝试重新连接到已断开连接的服务器</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">R:尝试重新连接到所有服务器</span></div>
<h3 align="left">3.3 配置</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">配置文件:/etc/motop.conf,可以有多个配置段,每一节都可以包含以下参数。</span></div>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> address:服务器的地址(必需)
<span style="color: rgba(0, 128, 128, 1)">2</span> username:登陆用户名
<span style="color: rgba(0, 128, 128, 1)">3</span> password:登陆用户密码
<span style="color: rgba(0, 128, 128, 1)">4</span> status:显示状态(默认开启)
<span style="color: rgba(0, 128, 128, 1)">5</span> replicationInfo:显示复制状态(默认值:开启)
<span style="color: rgba(0, 128, 128, 1)">6</span> replicaSet:显示副本集的状态(默认值:开启)
<span style="color: rgba(0, 128, 128, 1)">7</span> operations:显示操作(默认值:开启)
<span style="color: rgba(0, 128, 128, 1)">8</span> replicationOperations:不断展现主和从的复制操作(默认值:开启)
<span style="color: rgba(0, 128, 128, 1)">9</span> “DEFAULT”:是特殊的部分,参数可以在本节中设置为默认值。</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<h3 align="left">3.4 监控</h3>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 128, 1)">1</span> # motop -h                                #查看帮助
<span style="color: rgba(0, 128, 128, 1)">2</span> # vi /etc/motop.conf
<span style="color: rgba(0, 128, 128, 1)">3</span>
<span style="color: rgba(0, 128, 128, 1)">4</span> address=172.24.8.71
<span style="color: rgba(0, 128, 128, 1)">5</span> username=admin
<span style="color: rgba(0, 128, 128, 1)">6</span> password=admin
<span style="color: rgba(0, 128, 128, 1)">7</span> replicationInfo=off
<span style="color: rgba(0, 128, 128, 1)">8</span>
<span style="color: rgba(0, 128, 128, 1)">9</span>
<span style="color: rgba(0, 128, 128, 1)"> 10</span> address=172.24.8.72
<span style="color: rgba(0, 128, 128, 1)"> 11</span> username=admin
<span style="color: rgba(0, 128, 128, 1)"> 12</span> password=admin
<span style="color: rgba(0, 128, 128, 1)"> 13</span> replicationInfo=off</pre>
</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<h2 align="left">四 影响性能相关因素</h2>
<h3 align="left">4.1 锁</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">MongoDB用一个锁确保数据的一致性。但如果某种操作时间运行,其他请求和操作将不得不等待这个锁,导致系统性能降低。为了验证是否由于锁降低了性能,可以坚持serverStatus输出的globalLock部分的数据。如果参数globalLock.currentQueue.total的值一直较大,说明系统中有许多请求在等待锁,同时表明并发问题影响了系统的性能。</span></div>
<h3 align="left">4.2 内存</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">MongoDB通过内存映射数据文件,如果数据集很大,MongoDB将占用所有可用的系统内存。正式由于内存映射机制将内存的管理交给操作系统来完成,简化了MongoDB的内存管理,提高了数据库系统的性能,但是由于不能确定数据集的大小,需要多少内存也是个未知数。 </span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">通过serverStatus输出的关于内存使用状态方面的数据,我们能够深入地了解内存使用情况。检查参数mem.resident的值,如果超过了系统内存量并且还有大量的数据文件在磁盘上,表明内存过小。检查mem.mapped的值,如果这个值大于系统内存量,那么针对数据库的一些读操作将会引起操作系统的缺页操作,内存的换入换出将会降低系统的性能。</span></div>
<h3 align="left">4.3 连接数</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">有时候,客户端的连接数超过了MongoDB数据库服务器处理请求的能力,这也会降低系统的性能。可以通过serverStatus输出的关于连接数方面的参数进一步分析。参数globalLock.activeClients表示当前正在进行读写操作客户端的连接数,current表示当前客户端到数据库实例的连接数,available表示可用连接数。对于读操作大的应用程序,我们可以增加复制集成员数,将读操作分发到secondary节点上,对于写操作大的应用程序,可以通过部署分片集群来分发写操作。</span></div>
<h2 align="left">五 Web图形界面</h2>
<h3 align="left">5.1 开启Web</h3>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">从3.6版本后废弃了web界面,基于安全性考虑官方不推荐开启http。3.6之前的版本可参考官方方法开启:</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">https://docs.mongodb.com/v3.2/reference/configuration-options/</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left">&nbsp;</div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">参考链接:</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span style="font-family: 微软雅黑; font-size: small">https://www.cnblogs.com/littleatp/p/8419647.html</span></div>
<div style="line-height: 1.75; white-space: pre-wrap; -ms-word-break: normal" align="left"><span><span style="font-family: 微软雅黑; font-size: small">https://blog.csdn.net/Chen_Victor/article/details/74855050</span></span></div>

</div>
<div id="MySignature" role="contentinfo">
    <div style="background: #f7acbc; color: #0; font-size: small">
<p>
作者:木二
</p>
<p>
出处:http://www.cnblogs.com/itzgr/
</p>
<p>
关于作者:云计算、虚拟化,Linux,多多交流!
</p>
<p>
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接!如有其他问题,可邮件(xhy@itzgr.com)咨询。
</p>
</div><br><br>
来源:https://www.cnblogs.com/itzgr/p/11027176.html
頁: [1]
查看完整版本: 011.MongoDB性能监控