MongoDB Database Profiler
数据库profiler细粒度收集mongodb的写操作、游标、数据库命令等。可以在数据库级别或者实例级别开启profiling。
profiler将收集到的数据写入system.profile集合中。
profiling的级别:
0, 关闭profile,但是mongod会将超过slowOpThresholdMs的值操作写入日志
1, 只抓取slow操作,缺省是超过100毫秒的操作
2, 抓取所有数据库操作
1.查看是否开启profile功能:
> db.getProfilingLevel()
0
>
2.关闭profile功能:
> db.setProfilingLevel(0)
3.设置profile级别:
> db.setProfilingLevel(1,50)
{ "was" : 0, "slowms" : 100, "ok" : 1 }
>
setProfilingLevel的第一个参数是设置当前数据的profiling级别,第二个参数是设置整个mongod实例的慢操作阈值。
4.设置整个mongod的profiling级别
#启动时,指定参数profile的值
./mongod --profile=1 --slowms=15
示例:
查看profiler数据
数据库的profiler日志信息位于system.profile集合中。
> db.setProfilingLevel(1,50)
{ "was" : 1, "slowms" : 50, "ok" : 1 }
> db.profilingTest.insert({i:1})
WriteResult({ "nInserted" : 1 })
> db.profilingTest.find()
{ "_id" : ObjectId("56e3f62673c59411c4b1234c"), "i" : 1 }
> db.profilingTest.find({$where:'sleep(70)'})
> db.system.profile.find().pretty()
{
"op" : "insert",
"ns" : "test.currentOpTest",
"query" : {
"insert" : "currentOpTest",
"documents" : [
{
"_id" : ObjectId("56e3ebb713b6892d02827dde"),
"i" : 6411413
}
],
"ordered" : true
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"responseLength" : 25,
"protocol" : "op_command",
"millis" : 50,
"execStats" : { },
"ts" : ISODate("2016-03-12T10:13:11.073Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "insert",
"ns" : "test.currentOpTest",
"query" : {
"insert" : "currentOpTest",
"documents" : [
{
"_id" : ObjectId("56e3ebb713b6892d02827de6"),
"i" : 6411421
}
],
"ordered" : true
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"responseLength" : 25,
"protocol" : "op_command",
"millis" : 166,
"execStats" : { },
"ts" : ISODate("2016-03-12T10:13:11.252Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "insert",
"ns" : "test.currentOpTest",
"query" : {
"insert" : "currentOpTest",
"documents" : [
{
"_id" : ObjectId("56e3ed7e13b6892d028f10a4"),
"i" : 7235419
}
],
"ordered" : true
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"responseLength" : 25,
"protocol" : "op_command",
"millis" : 58,
"execStats" : { },
"ts" : ISODate("2016-03-12T10:20:46.223Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "insert",
"ns" : "test.currentOpTest",
"query" : {
"insert" : "currentOpTest",
"documents" : [
{
"_id" : ObjectId("56e3eea513b6892d02975bee"),
"i" : 7778981
}
],
"ordered" : true
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"responseLength" : 25,
"protocol" : "op_command",
"millis" : 149,
"execStats" : { },
"ts" : ISODate("2016-03-12T10:25:41.989Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "insert",
"ns" : "test.currentOpTest",
"query" : {
"insert" : "currentOpTest",
"documents" : [
{
"_id" : ObjectId("56e3f2bf13b6892d02b4401b"),
"i" : 9672402
}
],
"ordered" : true
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
},
"responseLength" : 25,
"protocol" : "op_command",
"millis" : 143,
"execStats" : { },
"ts" : ISODate("2016-03-12T10:43:11.201Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "insert",
"ns" : "test.profilingTest",
"query" : {
"insert" : "profilingTest",
"documents" : [
{
"_id" : ObjectId("56e3f62673c59411c4b1234c"),
"i" : 1
}
],
"ordered" : true
},
"ninserted" : 1,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2),
"w" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1),
"W" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"w" : NumberLong(1),
"W" : NumberLong(1)
}
}
},
"responseLength" : 25,
"protocol" : "op_command",
"millis" : 88,
"execStats" : { },
"ts" : ISODate("2016-03-12T10:57:42.769Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "query",
"ns" : "test.profilingTest",
"query" : {
"find" : "profilingTest",
"filter" : { }
},
"keysExamined" : 0,
"docsExamined" : 1,
"cursorExhausted" : true,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 0,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
},
"nreturned" : 1,
"responseLength" : 145,
"protocol" : "op_command",
"millis" : 94,
"execStats" : {
"stage" : "COLLSCAN",
"filter" : {
"$and" : [ ]
},
"nReturned" : 1,
"executionTimeMillisEstimate" : 0,
"works" : 3,
"advanced" : 1,
"needTime" : 1,
"needYield" : 0,
"saveState" : 0,
"restoreState" : 0,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 1
},
"ts" : ISODate("2016-03-12T10:57:55.996Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
{
"op" : "query",
"ns" : "test.profilingTest",
"query" : {
"find" : "profilingTest",
"filter" : {
"$where" : "sleep(70)"
}
},
"keysExamined" : 0,
"docsExamined" : 1,
"cursorExhausted" : true,
"keyUpdates" : 0,
"writeConflicts" : 0,
"numYield" : 1,
"locks" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(8)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(4)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(4)
}
}
},
"nreturned" : 0,
"responseLength" : 109,
"protocol" : "op_command",
"millis" : 1030,
"execStats" : {
"stage" : "COLLSCAN",
"filter" : {
"$where" : undefined
},
"nReturned" : 0,
"executionTimeMillisEstimate" : 70,
"works" : 3,
"advanced" : 0,
"needTime" : 2,
"needYield" : 0,
"saveState" : 1,
"restoreState" : 1,
"isEOF" : 1,
"invalidates" : 0,
"direction" : "forward",
"docsExamined" : 1
},
"ts" : ISODate("2016-03-12T10:58:07.439Z"),
"client" : "127.0.0.1",
"allUsers" : [ ],
"user" : ""
}
>
5.修改system.profile集合的大小
#1.关闭profiling
> db.setProfilingLevel(0)
#2.删除system.profile集合
> db.system.profile.drop()
#3.创建新得system.profile
> db.createCollection( "system.profile", { capped: true, size:4000000 } )
#4.重新开启profiling功能
> db.setProfilingLevel(1)
MongoDB Database Profiler的更多相关文章
- MongoDB 优化器MongoDB Database Profiler(12)
优化器profile 在MySQL 中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB 中是否有类似的功能呢?答案是肯定的,那就是MongoDB Database Profiler. 1 ...
- How do I drop a MongoDB database, from the command line?
mongo <dbname> --eval "db.dropDatabase()" > use mydb; > db.dropDatabase(); mon ...
- MongoDB性能优化
一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存在system.indexes 中,且默认总是为_id创建索引,它的索引使用基本和MySQL 等关系型数据库一样.其实可以这样说说,索引 ...
- Mongodb profile(慢查询日志)
在MySQL中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB中是否有类似的功能呢?答案是肯定的,那就是MongoDB Database Profiler.所以MongoDB 不仅有,而 ...
- MongoDB性能篇之创建索引,组合索引,唯一索引,删除索引和explain执行计划
这篇文章主要介绍了MongoDB性能篇之创建索引,组合索引,唯一索引,删除索引和explain执行计划的相关资料,需要的朋友可以参考下 一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存 ...
- MongoDB性能优化指南
一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存在system.indexes 中,且默认总是为_id创建索引,它的索引使用基本和MySQL 等关系型数据库一样.其实可以这样说说,索引 ...
- MongoDB 创建基础索引、组合索引、唯一索引以及优化
一.索引 MongoDB 提供了多样性的索引支持,索引信息被保存在system.indexes 中,且默认总是为_id创建索引,它的索引使用基本和MySQL 等关系型数据库一样.其实可以这样说说,索引 ...
- MongoDB分析工具之二:MongoDB分析器Profile
MongoDB优化器profile 在MySQL 中,慢查询日志是经常作为我们优化数据库的依据,那在MongoDB 中是否有类似的功能呢?答案是肯定的,那就是MongoDB Database Prof ...
- MongoDB监控之一:运行状态、性能监控,分析
为什么要监控? 监控及时获得应用的运行状态信息,在问题出现时及时发现. 监控什么? CPU.内存.磁盘I/O.应用程序(MongoDB).进程监控(ps -aux).错误日志监控 1.4.1 Mong ...
随机推荐
- 用xib自定义UITableViewCell的注意事项——重用
问题的提出: 有时候我们经常需要自定义tableView的cell,当cell里面的布局较为复杂时往往舍弃纯代码的方式而改用xib的方式进行自定义.当我们用纯代码的方式布局cell时,往往会在cell ...
- [转] <context-param>与<init-param>的区别与作用
看到一篇关于web.xm文件中标签的讲解,顺带还阐述了容器的工作流程,因此转载此,以供参考,原文地址:与的区别与作用 <context-param>的作用: web.xml的配置中< ...
- FTP客户端工具
推荐使用8UFTP.小.快.好! 8UFTP工具分为8UFTP客户端工具和 8UFTP智能扩展服务端工具,涵盖其它FTP工具所有的功能.不占内存,体积小,多线程,支持在线解压缩.界面友好,操作简单,可 ...
- Inno Setup入门(十八)——Inno Setup类参考(4)
http://379910987.blog.163.com/blog/static/3352379720112122533866/ 编辑框 编辑框也叫文本框,是典型的窗口可视化组件,既可以用来输入文本 ...
- Android内存优化10 内存泄漏常见情况1 静态泄漏
1,内存泄漏到本质是该释放的对象被持久化的对象引用了,造成持久化的常见情况有1,静态持久化 2,线程持久化 线程持久化 因为存活的线程是有dvk虚拟久直接持有,所以存活的线程都是持久化的 内存泄漏1: ...
- Ping Pod不通问题定位及Ingress验证
Ping Pod网络问题不通定位记录 1.验证墙是否通 flannel默认使用8285端口作为UDP封装报文的端口,VxLan使用8472端口,下面命令验证一下确定其在8472端口 ip -d lin ...
- Java操作xml文件的jar包dom4j
只能解析xml文件,不能解析普通的文件 https://www.cnblogs.com/sharpest/p/7877501.html
- mac下源码安装redis
转载:http://www.jianshu.com/p/6b5eca8d908b 下载安装包 redis-3.0.7.tar.gz 官网地址:http://redis.io/download 解压:t ...
- hibernate反向工程 (eclipse和myeclipse)【转】
myeclipse下hibernate反向工程: 1.选择myeclipse hibernate视图 2.建立与后台数据库的连接 1).configure database driver: 2).添加 ...
- javascript函数的四种调用模式及其this关键字的区别
方法调用模式: 当一个函数被保存为对象的一个属性时,我们称它为一个方法.当一个方法被调用时,this被绑定到该对象. //方法调用模式 var myObject = { value: 0 , incr ...