Mongodb profile

1:Profiling级别说明
0:关闭,不收集任何数据。 1:收集慢查询数据,默认是100毫秒。 2:收集所有数据
2: 开启Profiling和设置

1:通过mongo shell:
#查看状态:级别和时间
drug:PRIMARY> db.getProfilingStatus()
{ “was” : 1, “slowms” : 100 }
#查看级别
drug:PRIMARY> db.getProfilingLevel()
#设置级别
drug:PRIMARY> db.setProfilingLevel(2)
{ “was” : 1, “slowms” : 100, “ok” : 1 }
#设置级别和时间
drug:PRIMARY> db.setProfilingLevel(1,200)
{ “was” : 2, “slowms” : 100, “ok” : 1 }

以上要操作要是在test集合下面的话,只对该集合里的操作有效,要是需要对整个实例有效,则需要在所有的集合下设置或则在开启的时候开启参数:
2:不通过mongo shell:
mongod --profile=1 --slowms=15
或则在配置文件里添加2行:
profile = 1
slowms = 300
3:修改“慢查询日志”的大小

#关闭Profiling
drug:PRIMARY> db.setProfilingLevel(0)
{ “was” : 0, “slowms” : 200, “ok” : 1 }
#删除system.profile集合
drug:PRIMARY> db.system.profile.drop()
true
#创建一个新的system.profile集合
drug:PRIMARY> db.createCollection( “system.profile”, { capped: true, size:4000000 } )
{ “ok” : 1 }
#重新开启Profiling
drug:PRIMARY> db.setProfilingLevel(1)
{ “was” : 0, “slowms” : 200, “ok” : 1 }

输出说明

drug:PRIMARY> db.system.profile.find().pretty()
{
“op” : “query”, #操作类型,有insert、query、update、remove、getmore、command
“ns” : “mc.user”, #操作的集合
“query” : { #查询语句
“mp_id” : 5,
“is_fans” : 1,
“latestTime” : {
KaTeX parse error: Expected 'EOF', got '}' at position 17: …e" : 0 }̲, "late…gt” : 0
},
“$where” : “new Date(this.latestNormalTime)>new Date(this.replyTime)”
},
“cursorid” : NumberLong(“1475423943124458998”),
“ntoreturn” : 0, #返回的记录数。例如,profile命令将返回一个文档(一个结果文件),因此ntoreturn值将为1。limit(5)命令将返回五个文件,因此ntoreturn值是5。如果ntoreturn值为0,则该命令没有指定一些文件返回,因为会是这样一个简单的find()命令没有指定的限制。
“ntoskip” : 0, #skip()方法指定的跳跃数
“nscanned” : 304, #扫描数量
“keyUpdates” : 0, #索引更新的数量,改变一个索引键带有一个小的性能开销,因为数据库必须删除旧的key,并插入一个新的key到B-树索引
“numYield” : 0, #该查询为其他查询让出锁的次数
“lockStats” : { #锁信息,R:全局读锁;W:全局写锁;r:特定数据库的读锁;w:特定数据库的写锁
“timeLockedMicros” : { #锁
“r” : NumberLong(19467),
“w” : NumberLong(0)
},
“timeAcquiringMicros” : { #锁等待
“r” : NumberLong(7),
“w” : NumberLong(9)
}
},
“nreturned” : 101, #返回的数量
“responseLength” : 74659, #响应字节长度
“millis” : 19, #消耗的时间(毫秒)
“ts” : ISODate(“2014-02-25T02:13:54.899Z”), #语句执行的时间
“client” : “127.0.0.1”, #链接ip或则主机
“allUsers” : [ ],
“user” : “” #用户
}

日常查询

点击(此处)折叠或打开

#返回最近的10条记录
db.system.profile.find().limit(10).sort({ ts : -1 }).pretty()

#返回所有的操作,除command类型的
db.system.profile.find( { op: { $ne : ‘command’ } } ).pretty()

#返回特定集合
db.system.profile.find( { ns : ‘mydb.test’ } ).pretty()
郑州不孕不育医院:http://wapyyk.39.net/zz3/zonghe/1d427.html
#返回大于5毫秒慢的操作
db.system.profile.find( { millis : { $gt : 5 } } ).pretty()

#从一个特定的时间范围内返回信息
db.system.profile.find(
{
ts : {
$gt : new ISODate(“2012-12-09T03:00:00Z”) ,
$lt : new ISODate(“2012-12-09T03:40:00Z”)
}
}
).pretty()

#特定时间,限制用户,按照消耗时间排序
db.system.profile.find(
{
ts : {
$gt : new ISODate(“2011-07-12T03:00:00Z”) ,
$lt : new ISODate(“2011-07-12T03:40:00Z”)
}
},
{ user : 0 }
).sort( { millis : -1 } )

猜你喜欢

转载自blog.csdn.net/cyxhjy1314/article/details/91374258
今日推荐