日志

通过启动时指定参数-v[--verbose]控制日志级别,值为v、vv、vvv、vvvv、vvvvv,v越多日志越详细(记录到mongodb日志中)。

explain--单次解析

单次查询find()后接.explain()。mongodb 3.0之后修更新了explain()方法,可传入不同参数查找,参考资料

> db.test.find().explain() --可选参数queryPlanner、executionStats、allPlansExecution

profile--慢查询

查询profile级别(记录到数据库中,表system.profile),profile有三个级别(0-关闭/1-超过slowms毫秒的查询/2-所有查询)。

> db.getProfilingStatus()
{ "was" : 0, "slowms" : 100 }

设置profile级别。

> db.setProfilingLevel(1)
{ "was" : 0, "slowms" : 100, "ok" : 1 }

设置slowms(mongod启动参数)。

$ ./mongod --slowms arg (=100)

mongostat--实时监控

连接参数。

$ ./mongostat [options] args
#别名   options     args
-h      --host      hostname
        --port      port
-u      --username  username
-p      --password  password

执行结果,其中insert代表每秒插入多少条数据,qr|qw代表读|写队列。

insert query update delete getmore command % dirty % used flushes  vsize   res qr|qw ar|aw netIn netOut conn                      time
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:12+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:13+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:14+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:15+08:00
*0    *0     *0     *0       0     2|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0  133b    18k    1 2015-12-23T00:05:16+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:17+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:18+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:19+08:00
*0    *0     *0     *0       0     1|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0   79b    18k    1 2015-12-23T00:05:20+08:00
*0    *0     *0     *0       0     2|0     0.0    0.0       0 364.0M 70.0M   0|0   0|0  133b    18k    1 2015-12-23T00:05:21+08:00