MongoDB Series-Governance Mongodb->db.currentop ()

Source: Internet
Author: User

MongoDB Series-Management Mongodb->db.currentop ()

Management Mongodb->db.currentop (), is absolutely original ...

today, the DBA in the company shares a good view of how control management (leveraging the Inntop tool) is performed for each of the specific CRUD statements on MySQL . Here, I also caught dead, in MongoDB How to manage the specific each crud operation (such as a query statement slow, too much resources, can kill it directly, this seems very violent ha, but it doesn't matter, sometimes forced to ... However, MongoDB is not a third-party tool Oh, but home implementation of the function, top ... )

Currentop is a good thing, as the name implies, is the current operation. In MongoDB, you can view the operation statement information at the moment on the current database, including Insert/query/update/remove/getmore/command and many other operations. Direct execution db.currentop () generally returns an empty array, we can specify a parameter of true, which returns the user connections the operation associated with the system Cmmand. Here's a look:

The Execute command returns an array of InProg, each of which is a nested document, with one as an example, explaining the specific meaning:

{

"Opid": 37432,//the ID of this operation

"Active": false,//whether this action is active

"Secs_running": 0,//How many seconds this operation has run

"OP": "Query",//specific operational behavior, including (Insert/query/update/remove/getmore/command)

"NS": "Category.categorydocs",//namespace of this operation, database name. Collection Name

Specific action statements

"Query": {

"CNAME": "Spore",

"Sort": 2

},

"Client": "*.*.*.*:21758",//connection of clients information

"desc": "conn724",//Database connection description

"ThreadId": "0x78156940",//thread ID

"ConnectionID": 724,//database connection ID

"Waitingforlock": false,//is waiting to acquire the lock,

"Numyields": 0,

"Lockstats": {

"Timelockedmicros": {//This operation obtains the following lock after the control of the microsecond time

"R": Numberlong (0),//global read lock for the entire MongoDB service instance

"W": Numberlong (0),// Global write lock for entire MongoDB service instance

"R": Numberlong (170),//read lock for entire DB instance

"W": Numberlong (0)//write lock for entire DB instance

},

"Timeacquiringmicros": {//This operation in order to obtain the following lock, and the time spent waiting for the microsecond

"R": Numberlong (),// Global read lock for the entire MongoDB service instance

"W": Numberlong (),// Global write lock for the entire MongoDB service instance

"R": Numberlong (5),//read lock for entire DB instance

"W": Numberlong (0),//write lock for entire DB instance

}

}

}

Time Unit conversion:

1 seconds =1000 milliseconds (ms) 1 msec =1/1,000 sec (s)

1 sec =1,000,000 microseconds (μs) 1 μs =1/1,000,000 sec (s)

In fact, we can write a script to filter the InProg array to get the data we want, such as:

1:--gets the stopped activity + operation for the queried data

Db.currentop (True). Inprog.foreach (

function (Opdoc) {//opdoc is actually the return of each OP action object

if (!opdoc.active && opdoc.op== ' query ')

Printjson (d)//print information

}

)

2:--in progress + operation for query data

Db.currentop (True). Inprog.foreach (

function (Opdoc) {//opdoc is actually the return of each OP action object

if (opdoc.active && opdoc.op== ' query ')

Printjson (d)//print information

}

)

Through the above monitoring if you find a slow operation, you can also kill, very simple, know the specific opid, a command can be done, so easy:

Db.killop (opid)//kill The current operation Opid for the specific operation ID number, of course, only kill is in progress

Well, first write so much, have the time to continue to write their own experience in MongoDB, write down for nothing else, just for the first brother less detours ....

Http://www.myexception.cn/database/1260955.html

MongoDB Series-Governance Mongodb->db.currentop ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.