Is it possible to see the incoming queries in mongodb to debug/trace issues?

别来无恙 提交于 2021-01-29 05:09:59

问题


I have mongo running on my macbook (OSX).

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.


回答1:


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. Database Profiler

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.

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".

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 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 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

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

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.



来源:https://stackoverflow.com/questions/61239538/is-it-possible-to-see-the-incoming-queries-in-mongodb-to-debug-trace-issues

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!