是否可以在 mongodb 中查看传入查询以调试/跟踪问题? [英] Is it possible to see the incoming queries in mongodb to debug/trace issues?

查看:48
本文介绍了是否可以在 mongodb 中查看传入查询以调试/跟踪问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 macbook (OSX) 上运行着 mongo.

I have mongo running on my macbook (OSX).

是否可以运行某种监视器"来向我的 mongodb 显示任何收入请求?

Is it possible to run some kind of a 'monitor' that will display any income requests to my mongodb?

我需要跟踪我的应用程序是否具有正确的查询格式.

I need to trace if I have the correct query formatting from my application.

推荐答案

您会发现这些工具(或实用程序)可用于监视和诊断目的.除了 mtools 之外的所有工具都打包在 MongoDB 服务器中(有时它们是单独安装的).

You will find these tools (or utilities) useful for monitoring as well as diagnosing purposes. All the tools except mtools are packaged with MongoDB server (sometimes they are installed separately).

1.数据库分析器

探查器存储进入数据库的每个 CRUD 操作;默认情况下它是关闭的.戴上它是相当昂贵的;它把每一次读都变成读+插入,每一次写都变成写+插入.注意:保持打开状态可能会因传入操作而迅速压倒服务器 - 使 IO 饱和.

The profiler stores every CRUD operation coming into the database; it is off, by default. Having it on is quite expensive; it turns every read into a read+insert, and every write into a write+insert. CAUTION: Keeping it on can quickly overpower the server with incoming operations - saturating the IO.

但是,它是一个非常有用的工具,可以在短时间内用于查找数据库操作的情况.建议在开发环境中使用.

But, it is a very useful tool when used for a short time to find what is going on with database operations. It is recommended to be used in development environments.

可以使用命令 db.getProfilingLevel() 访问分析器设置.要激活配置文件,请使用 db.setProfilingLevel(level) 命令.验证分析器在 db.system.profile 集合中捕获的内容;您可以使用 findaggregate 方法像任何其他集合一样查询它.db.system.profile 文档字段op 指定了数据库操作的类型;例如,对于查询,它是查询".

The profiler setting can be accessed by using the command db.getProfilingLevel(). To activate the profilre use the db.setProfilingLevel(level) command. Verify what is captured by the profiler in the db.system.profile collection; you can query it like any other collection using the find or aggregate methods. The db.system.profile document field op specifies the type of database operation; e.g., for queries it is "query".

分析器具有三个级别:0 未捕获任何信息(或已关闭并默认).1 捕获每个超过 100 毫秒的查询.2 捕获每个查询;这可用于查找进入的实际负载.

The profiler has three levels: 0is not capturing any info (or is turned off and default). 1 captures every query that takes over 100ms. 2 captures every query;this can be used to find the actual load that is coming in.

2.mongoreplay

mongoreplay 是一个流量捕获和重放工具,用于MongoDB,您可以使用它来检查和记录发送到 MongoDB 实例的命令,然后稍后将这些命令重放回另一台主机上.注意:适用于 Linux 和 macOS.

mongoreplay is a traffic capture and replay tool for MongoDB that you can use to inspect and record commands sent to a MongoDB instance, and then replay those commands back onto another host at a later time. NOTE: Available for Linux and macOS.

3.mongostat

mongostat 命令行实用程序提供状态的快速概览当前正在运行的 mongod 实例.

mongostat commad-line utility provides a quick overview of the status of a currently running mongod instance.

您可以实时查看传入的操作.默认情况下,每秒都会显示统计信息.有多种选项可以自定义输出、时间间隔等.

You can view the incoming operations in real-time. The statistics are displated, by default every second. There are various options to customize the output, the time interval, etc.

4.工具

mtools 是帮助脚本的集合,用于解析、过滤和可视化(直通图)MongoDB日志文件.

mtools is a collection of helper scripts to parse, filter, and visualize (thru graphs) MongoDB log files.

您会发现 mlogfilter 脚本很有用;它使用各种命令选项减少了来自 MongoDB 日志文件的信息量.例如,mlogfilter mongod.log --operation query 仅通过 query 操作过滤日志.

You will find the mlogfilter script useful; it reduces the amount of information from MongoDB log files using various command options. For example, mlogfilter mongod.log --operation query filters the log by query operations only.

这篇关于是否可以在 mongodb 中查看传入查询以调试/跟踪问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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