rueckstiess / mtools

A collection of scripts to set up MongoDB test environments and parse and visualize MongoDB log files.
Apache License 2.0
1.89k stars 403 forks source link

Where control the slow log in the logs/mongodb.log #874

Closed czxin788 closed 2 years ago

czxin788 commented 2 years ago

We know that mongodb can view slow SQL as follows:

db.setProfilingLevel(1)
db.system.profile.find( { millis : { $gt : 5 } } )

But why in logs/mongodb also contains slow SQL. Where is the slow SQL controlled tail logs/mongodb.log 2022-06-07T02:25:15.295+0800 I COMMAND [conn36586321] command db1.form command: find { find: "form", filter: { templateId: "0daefxxxxxxxx, formName: "xxxx" }, limit: 1, singleBatch: true, $db: "db1" } planSummary: COLLSCAN keysExamined:0 docsExamined:108021 cursorExhausted:1 numYields:847 nreturned:0 reslen:241 locks:{ Global: { acquireCount: { r: 848 } }, Database: { acquireCount: { r: 848 } }, Collection: { acquireCount: { r: 848 } } } protocol:op_query 1297ms

stennie commented 2 years ago

Hi @czxin788,

Your question appears to be about general MongoDB behaviour so I would suggest the MongoDB Community Forums as a better channel for broader questions.

The system.profile collection is a capped collection (default is 1MB) which captures some details about queries on a per-database level. See Database Profiler documentation for more information.

Slow queries are logged to the system log and the system.profile collection (if profiling is enabled) based on the value of the global operationProfiling.slowOpThresholdMs value which defaults to 100 ms.

Please check the server documentation for your version of MongoDB for available profiling and logging configuration options.

Regards, Stennie