MongoDB记录所有查询 [英] MongoDB logging all queries

查看:246
本文介绍了MongoDB记录所有查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题很简单,就这么简单...如何在mongodb中的可尾"的日志文件中记录所有查询?

The question is as basic as it is simple... How do you log all queries in a "tail"able log file in mongodb?

我尝试过:

  • 设置配置级别
  • 设置慢速ms参数启动
  • 带有-vv选项的mongod

/var/log/mongodb/mongodb.log继续仅显示当前活动连接数...

The /var/log/mongodb/mongodb.log keeps showing just the current number of active connections...

推荐答案

我最终通过像这样启动mongod来解决了这个问题(锤子又丑陋,是的,但是适用于开发环境)

I ended up solving this by starting mongod like this (hammered and ugly, yeah... but works for development environment):

mongod --profile=1 --slowms=1 &

这将启用性能分析并将慢速查询"的阈值设置为1ms,从而导致所有查询都作为慢速查询"记录到文件:

This enables profiling and sets the threshold for "slow queries" as 1ms, causing all queries to be logged as "slow queries" to the file:

/var/log/mongodb/mongodb.log

现在我可以使用以下命令获得连续的日志输出:

Now I get continuous log outputs using the command:

tail -f /var/log/mongodb/mongodb.log

示例日志:

Mon Mar  4 15:02:55 [conn1] query dendro.quads query: { graph: "u:http://example.org/people" } ntoreturn:0 ntoskip:0 nscanned:6 keyUpdates:0 locks(micros) r:73163 nreturned:6 reslen:9884 88ms

这篇关于MongoDB记录所有查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆