码迷,mamicode.com
首页 > 数据库 > 详细

mongodb监控常用方法

时间:2018-02-06 01:12:25      阅读:374      评论:0      收藏:0      [点我收藏+]

标签:each   访问   涵盖   ati   enc   profiling   9.1   read   分布   

列举mongodb监控的常用命令

1.监控统计

mongostat 可用于查看当前QPS/内存使用/连接数,以及多个shard的压力分布

命令参考

./mongostat --port 27071  -u admin -p xxx --authenticationDatabase=admin --discover -n 30 3

参数说明
-discover 提供集群中所有节点的状态
-n 30 3 表示输出30次,每次休眠3秒钟

输出示例

                   insert query update delete getmore command  %dirty  %used flushes mapped vsize   res faults qr|qw  ar|aw netIn netOut conn    set repl                      time
185.1.12.101:10001    499  4886   2042   1612     237   756|0     3.8   80.1       0        28.5G 19.1G    n/a   3|0    1|1    4m     7m 5545 shard0  PRI 2017-03-06T11:48:17+08:00

指标说明

指标名 说明
inserts/s 每秒插入数
query/s 每秒查询数
update/s 每秒更新数
delete/s 每秒删除数
getmore/s 每秒getmore数
command/s 每秒命令数,涵盖了增删改查和其他操作
dirty/% WriedTiger引擎参数,缓存中无效数据百分比
used/% WriedTiger引擎参数,正在使用的缓存百分比
flushs/s 每秒执行fsync将数据写入硬盘次数
mapped/MB 所有的被mmap的数据量
vsize/MB 虚拟内存使用量
res/MB 物理内存使用量
faults/s 每秒访问失败数,与内存swap有关
qrqw 客户端读写等待队列数量,高并发时,一般队列值会升高
araw 客户端读写活跃个数
netIn 网络接收数据量
netOut 网络发送数据量
conn 当前连接数
set 所属集合(分片)
repl 复制状态(主节点/二级节点..)
time 时间戳

官方说明
https://docs.mongodb.com/manual/reference/program/mongostat/

2.热点操作

mongotop 用于查看当前占用比例较高的DB操作,即热点操作。

命令参考

./mongotop --port 10001  -u admin -p xxx --authenticationDatabase=admin

输出示例

    ns                  total   read    write   2017-03-20T15:22:36+08:00
    nscl.T_De**ata      407ms   266ms   140ms                             
    nscl.T_OAUT**EN     251ms   242ms   8ms                             
    nscl.T_Subs**tion   180ms   180ms   0ms                             
    nscl.T_De**istory   61ms    0ms     61ms                             

官方说明
https://docs.mongodb.com/manual/reference/program/mongotop/

3.慢操作检测

profile是mongodb实现慢操作检测的模块,官方说明

连接shell(使用root)

./mongo --port 10001  -u root -p xxx --authenticationDatabase=admin
use admin

注意
profile操作必须连接mongod进程,而mongos无法执行此类操作

profile设置

db.setProfilingLevel(0) 不输出慢查询
db.setProfilingLevel(1,100) 统计慢查询,100ms是阈值
db.setProfilingLevel(2) 统计所有操作
db.getProfilingLevel()

查询慢查询

db.system.profile.find().limit(10).sort( { ts : -1 } ).pretty() 
db.system.profile.find().limit(10).sort( { millis : -1 } ).pretty()

查询当前操作

db.currentOp()
  • 样例-查询等待锁的增删改查

    db.currentOp(
       {
     "waitingForLock" : true,
     $or: [
        { "op" : { "$in" : [ "insert", "update", "remove" ] } },
        { "query.findandmodify": { $exists: true } }
    ]
       }
    )
  • 样例-查询活跃query操作

    db.currentOp(true).inprog.forEach(
       function(opDoc){
     if(!opDoc.active && opDoc.op=='query')
        printjson(d)
     }
     )

    currentOp更多说明

4. 集合状态分析

数据库状态

db.stats()
->
{ 
  "db" : "test",           //当前数据库 
  "collections" : 3,       //集合数量 
  "objects" : 165606718,   //对象数量 
  "avgObjSize" : 381,      //对象平均大小 
  "dataSize" : 63142130610, //所有数据总大小 
  "storageSize" : 16384,    //数据占磁盘大小 
  "numExtents" : 3, 
  "indexes" : 479,          //索引数 
  "indexSize" : 8011636736, //索引大小 
  "fileSize" : 201326592    //预分配给数据库的文件大小 
} 

集合状态

db.xxx.stats()
->
   ...
    "sharded" : true,      //是否分片
    "capped" : false,      //是否限制大小
    "ns" : "nscl.T_BUSINESS_LOG",
    "count" : 26541837,         //表数量
    "size" : 14991828070,       //表大小
    "storageSize" : 3615076352, //占磁盘大小
    "totalIndexSize" : 2640109568, //索引大小
    "avgObjSize" : 564.8376210734773,
    "nindexes" : 6,
    "nchunks" : 374         //chunk数量
   ...

mongodb监控常用方法

标签:each   访问   涵盖   ati   enc   profiling   9.1   read   分布   

原文地址:https://www.cnblogs.com/littleatp/p/8419647.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!