Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

MongoDB monitoring items-- how to use commands to get

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. View the running status of server threads

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.currentOp ());"

When you find that the secs_running field has a large value and seriously blocks other threads of the system from running, you can first kill it using db.killOp (opid), and then optimize it for the query executed by this link.

There are many links inside a running mongodb server, and directly executing db.currentOp () will print out all the link information, which is not easy to find out the problematic links, so you must deal with the information output by db.currentOp ().

Here are some information processing scripts

Find out the link information that runs longer than 200ms

Mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); db.currentOp (true) .inprog.forEach (function (doc) {if (doc.active==true&& doc.secs_running > 200) {printjson (doc)});"

If you only need to type out a field of these links, you can use print directly.

Mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); db.currentOp (true) .inprog.forEach (function (doc) {if (doc.active==true&& doc.secs_running > 200) {printjson (doc.opid)});"

Print client information

Mongo-- host=-- port=-u mongo_monitor-p "--authenticationDatabase admin payDB-eval" rs.slaveOk (); db.currentOp (true). Inprog.forEach (

Function (opDoc) {

If (opDoc.client)

Printjson (opDoc.client)

}

); "

You can also get the information that the activity has stopped and the operation behavior is query in the current operation.

Mongo-- host=-- port=-u mongo_monitor-p "--authenticationDatabase admin payDB-eval" rs.slaveOk (); db.currentOp (true). Inprog.forEach (

Function (opDoc) {/ / opDoc is actually every op Operand returned

If (! opDoc.active&&opDoc.op=='query')

Printjson (opDoc)

}

); "

You can also get the information of the current operation, which is in progress and whose behavior is query.

$mongo-- host=-- port=-u mongo_monitor-p "--authenticationDatabase admin payDB-eval" rs.slaveOk (); db.currentOp (true). Inprog.forEach (

Function (opDoc) {/ / opDoc is actually every op Operand returned

If (opDoc.active&&opDoc.op=='query')

Printjson (opDoc)

}

); "

View the information for database payDB:

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.currentOp ());"

View the number of connections

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus () .connections);"

Show all the operations waiting for the lock:

Mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); db.currentOp () .inprog.forEach (function (item) {if (item.waitingForLock) print (JSON.stringify (item))});"

Lock information

Mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus () .locks);"

Global lock information

$mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus (). GlobalLock

); "

Memory information

$mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus (). Mem

); "

Index statistics

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus () .indexCounters);"

The network

Mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus () .network);"

Replication set

$mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus (). Repl

); "

Replication set determines which IP is primary

$mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus (). Repl

); "| grep primary

Operation counter

$mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus (). Opcounters

); "

Journal (dur) persistence

$mongo-- host=-- port=-u mongo_monitor-p ""-- authenticationDatabase admin payDB-eval "rs.slaveOk (); printjson (db.serverStatus (). Dur

); "

View oplog information:

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin local-eval "rs.slaveOk (); printjson (db.oplog.rs.stats ())

); "

This IP does not need to be modified. This is primary.

View oplog metadata information for master:

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin admin-eval "rs.slaveOk (); printjson (db.printReplicationInfo ())

); "

Modify to any IP

View the synchronization status of slave-delay:

$mongo-host=-port=-u mongo_monitor-p ""-- authenticationDatabase admin local-eval "rs.slaveOk (); printjson (db.printSlaveReplicationInfo ())

); "

Command is used to track the real-time health of the database instance

Mongostat-host=-port=-u mongo_monitor-p ""-authenticationDatabase admin

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report