这个问题既简单又基本。如何将所有查询记录在mongodb中的“尾部”日志文件中?
我试过:
设置概要级别 设置启动慢ms参数 使用-vv选项Mongod
/var/log/mongodb/mongodb.log一直显示当前活动连接的数量…
这个问题既简单又基本。如何将所有查询记录在mongodb中的“尾部”日志文件中?
我试过:
设置概要级别 设置启动慢ms参数 使用-vv选项Mongod
/var/log/mongodb/mongodb.log一直显示当前活动连接的数量…
当前回答
MongoDB有一个复杂的性能分析功能。日志记录发生在系统中。配置文件收集。日志内容如下:
db.system.profile.find()
有3个日志级别(源):
Level 0 - the profiler is off, does not collect any data. mongod always writes operations longer than the slowOpThresholdMs threshold to its log. This is the default profiler level. Level 1 - collects profiling data for slow operations only. By default slow operations are those slower than 100 milliseconds. You can modify the threshold for “slow” operations with the slowOpThresholdMs runtime option or the setParameter command. See the Specify the Threshold for Slow Operations section for more information. Level 2 - collects profiling data for all database operations.
要查看数据库运行在哪个分析级别,请使用
db.getProfilingLevel()
并查看状态
db.getProfilingStatus()
要更改分析状态,使用该命令
db.setProfilingLevel(level, milliseconds)
其中level指的是分析级别,毫秒是需要记录查询持续时间的ms。若要关闭日志记录,请使用
db.setProfilingLevel(0)
在系统概要集合中查找耗时超过一秒的所有查询(按时间戳降序排序)的查询将为
db.system.profile.find( { millis : { $gt:1000 } } ).sort( { ts : -1 } )
其他回答
db.setProfilingLevel(2,-1)
这个工作!它在mongod日志文件中记录了所有查询信息
我建议你看看mongosniff。这个工具可以做任何你想做的事情,甚至更多。特别是它可以帮助诊断大规模mongo系统的问题,以及查询是如何路由的以及它们来自哪里,因为它是通过监听您的网络接口进行所有与mongo相关的通信来工作的。
http://docs.mongodb.org/v2.2/reference/mongosniff/
将profilinglevel设置为2是记录所有查询的另一个选项。
db.adminCommand( { getLog: "*" } )
Then
db.adminCommand( { getLog : "global" } )
尝试这个包来跟踪所有查询(没有oplog操作):https://www.npmjs.com/package/mongo-tail-queries
(免责声明:我写这个包正是为了这个需要)