MongoDB 常用故障排查工具

MongoDB故障排查工具概览
本文介绍MongoDB中用于故障排查的多种工具,包括Profiler、Mongostat、Mongoop、mongoperf等,详细解释了它们的功能、使用方法及应用场景,帮助DBA和开发者有效监控和优化MongoDB性能。
1.profile
profiling levels

         0,关闭profile1,只抓取slow查询;2,抓取所有数据。

启动profile并且设置Profile级别:

     可以通过mongo shell启动,也可以通过驱动中的profile命令启动,启动后记录会被保存在system.profile collection下,可以使用db.setProfilingLevel来启动。默认slow100   毫秒。db.setProfilingLevel可以有2个参数,第一个参数指定Profiling 级别,第二个参     数指定slow阀值。

         检查当前Profiling 级别:可以通过db.getProfilingStatus()获取当前profiling级别,slowms      标记慢查询阀值。

         关闭Profiling还是使用db.setProfilingLevel(0)来关闭profiling

         整个实例开启Profilingmongod --prifile=1 --slowms=15

         shardProfiling:对shardprofiling要对每一个实例进行profiling

查看Profiling数据

         可以直接在system.profilecollection上查看如:db.systen.profile.find()。或者使用show        profile,会显示最近至少1ms时间运行的前5条记录。

Profiler概述

         要修改system.profile collection的大小必须:1.关闭profiling2.删除system.profile3.然后重新创建system.profile4.重启profile

         shell如下:db.setProfilingLevel(0)

         ,db.system.profile.drop()

         ,db.createCollect("system.profile",{cappedLtrue,size:4000000})

         ,db.setProfilingLevel(1)

2.Mongostat
mongostat n n:刷新秒数 反应当前mongod的负荷
 
 
inserts      - # of inserts per second (* means replicated op)
query        - # of queries per second
update       - # of updates per second
delete       - # of deletes per second
getmore      - # of get mores (cursor batch) per second
command      - # of commands per second, on a slave its local|replicated
flushes      - # of fsync flushes per second
mapped       - amount of data mmaped (total data size) megabytes
vsize        - virtual size of process in megabytes
res          - resident size of process in megabytes
faults       - # of pages faults per sec
locked       - name of and percent time for most locked database
idx miss     - percent of btree page misses (sampled)
qr|qw        - queue lengths for clients waiting (read|write)
ar|aw        - active clients (read|write)
netIn        - network traffic in - bits
netOut       - network traffic out - bits
conn         - number of open connections
set          - replica set name
repl         - replication type
                  PRI - primary (master)
                  SEC - secondary
                  REC - recovering
                  UNK - unknown
                  SLV - slave
                  RTR - mongos process ("router")
 
3.Mongoop
collection级别反应,读写的时间
http://docs.mongodb.org/manual/reference/program/mongotop/
mongotop -h 192.168.10.69 2,每间隔2秒返回一次结果
                     ns       total        read       write              2014-05-09T14:00:55
    ub1405.system.users         0ms         0ms         0ms
  ub1405.system.profile         0ms         0ms         0ms
b1405.system.namespaces         0ms         0ms         0ms
  ub1405.system.indexes         0ms         0ms         0ms
    ub1405.WapRecommend         0ms         0ms         0ms
   ub1405.VisitPageInfo         0ms         0ms         0ms
       ub1405.UsageInfo         0ms         0ms         0ms
     ub1405.UpgradeInfo         0ms         0ms         0ms
          ub1405.Switch         0ms         0ms         0ms
 

 

4.mongoperf

用来测试io性能,可以用来做mongo的io压力测试,和sql server的SQLIOSim
http://docs.mongodb.org/manual/reference/program/mongoperf/
 
5. ServerStatus db.serverStatus()
 
包含了很多信息
 
6.db.stats()
 
反应数据库所占用的存储
{
        "db" : "ub1405",
        "collections" : 17,
        "objects" : 9939344,
        "avgObjSize" : 336.2453477815035,
        "dataSize" : 3342058180,
        "storageSize" : 4501643264,
        "numExtents" : 111,
        "indexes" : 15,
        "indexSize" : 322633136,
        "fileSize" : 8519680000,
        "nsSizeMB" : 16,
        "dataFileVersion" : {
                "major" : 4,
                "minor" : 5
        },
        "ok" : 1
}
 
7.db.collection.stats()
返回collection的一些信息:
{
        "ns" : "ub1405.WapRecommend",
        "count" : 514,
        "size" : 174416,
        "avgObjSize" : 339.3307392996109,
        "storageSize" : 430080,
        "numExtents" : 3,
        "nindexes" : 1,
        "lastExtentSize" : 327680,
        "paddingFactor" : 1,
        "systemFlags" : 1,
        "userFlags" : 0,
        "totalIndexSize" : 24528,
        "indexSizes" : {
                "_id_" : 24528
        },
        "ok" : 1
}
posted on 2014-05-11 09:49  Fanr_Zh 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/Amaranthus/p/3721392.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值