Mongostat will output the current mongodb running status regularly
Mongostat -h X.X.X.X :27017 -u root -p123456 -h: specify the IP address and port you can use --port to specify the port number. -u: if authentication is enabled, enter the user name -p: passwordCopy the code
Example output:
Important field explanations and concerns:
- Insert: The number of objects inserted into the database per second. If it is slave, the value preceded by * indicates the replication set operation
- Query: Indicates the number of query operations per second
- Update: indicates the number of update operations per second
- Delete: indicates the number of deletion operations per second
- Getmore: GetMore operands per second to query cursor
- Dirty: Cache percentage of dirty data bytes (WiredTiger engine only)
- Used: percentage of caches in use (WiredTiger engine only)
- Flushes :(only for the WiredTiger engine) flushes the number of checkpoint triggers in a polling interval. Generally 0, indirect 1. Flush is expensive and can cause problems if flushed frequently
- Vsize: indicates the virtual memory usage
- Res: Physical memory usage
- Arw: number of active clients performing read and write operations
- QRW: queue length for clients to read and write data from the mongodb instance
- Net_in: network incoming traffic of mongo instances
- Net_out: network outgoing traffic of mongo instance
- Conn: The recommended number of open connections is less than 5000
View logs:
Start by finding the logpath definition in the mongod. Conf file. Then view the log file in the corresponding path
To set the log level:
db.setLogLevel(<level>, <component>)
level int
0 is the mongodb default log level
-1 all level
1 to 5 include debug message
Copy the code
Enable slow request:
Db. setProfilingLevel(level) -0 disable - 1 record slow SQL (default: >100ms) - 2 record all commands db.setProfilingLevel(1,10) enables slow query and records statements that exceed 10msCopy the code
View slow query:
db.system.profile.find({}}); Db.system.profile. find({millis: {$gt:5}}); Db.system.profile.find ().sort({$natrual: -1}).limit(3); db.system.profile.find().sort({$natrual: -1}). Db.system.profile.find ().sort({$natural:-1}).limit(1); View the latest record {"ts" : ISODate(" 2012-05-20T16:50:36.321z "), "info" : "query test.system.profile reslen:1219 nscanned:8 \nquery: { query: {}, orderby: { $natural: -1.0}} Nreturned :8 bytes:1203", "millis" : 0} -ts: timestamp -info: specific operation -millis: time, millisecondsCopy the code
Analyze the requests mongodb is executing:
db.currentOp();
{
"desc" : "conn632530",
"threadId" : "140298196924160",
"connectionId" : 632530,
"client" : "11.192.159.236:57052",
"active" : true,
"opid" : 1008837885,
"secs_running" : 0,
"microsecs_running" : NumberLong(70),
"op" : "update",
"ns" : "mygame.players",
"query" : {
"uid" : NumberLong(31577677)
},
"numYields" : 0,
"locks" : {
"Global" : "w",
"Database" : "w",
"Collection" : "w"
},
....
}
Copy the code
Key concerns
field | meaning |
---|---|
client | Which client initiates the request? |
opid | The unique identifier of the operation. |
secs_running | Indicates the time when the operation has been performed, in seconds. If the value returned by this field is particularly large, check whether the request is reasonable. |
microsecs_running | Indicates the time when the operation has been performed, in microseconds. If the value returned by this field is particularly large, check whether the request is reasonable. |
ns | The operation target collection. |
op | Represents the type of operation. It is usually one of query, insert, update, delete. |
locks | Lock-related information |