1:查看MongoDB当前正在做哪些操作?
db.currentOp() 等同于: db.$cmd.sys.inprog.findOne()
2:查看当前有多少个连接?
db.serverStatus().connections
3:详解currentOp()
gechongrepl:PRIMARY> db.currentOp() { "inprog" : [ { "opid" : 6222, "active" : true, "secs_running" : 3, "microsecs_running" : NumberLong(3662328), "op" : "getmore", "ns" : "local.oplog.rs", "query" : { }, "client" : "192.168.91.132:45745", "desc" : "conn5", "threadId" : "0x7f1370cb4700", "connectionId" : 5, "waitingForLock" : false, "numYields" : 0, "lockStats" : { "timeLockedMicros" : { "r" : NumberLong(141), "w" : NumberLong(0) }, "timeAcquiringMicros" : { "r" : NumberLong(16), "w" : NumberLong(0) } } } ] }
"opid" : 6222,#进程号
"active" : true,#是否活动状态
"secs_running" : 3,#操作运行了多少秒
"microsecs_running" : NumberLong(3662328),
"op" : "getmore",#操作类型,包括(insert/query/update/remove/getmore/command)
"ns" : "local.oplog.rs",#命名空间
"query" : {},#如果op是查询操作,这里将显示查询内容;也有说这里显示具体的操作语句的
"client" : "192.168.91.132:45745",#连接的客户端信息
"desc" : "conn5",#数据库的连接信息
"threadId" : "0x7f1370cb4700",#线程ID
"connectionId" : 5,#数据库的连接ID
"waitingForLock" : false,#是否等待获取锁
"numYields" : 0,
"lockStats" : {
"timeLockedMicros" : {#持有的锁时间微秒
"r" : NumberLong(141),#整个MongoDB实例的全局读锁
"w" : NumberLong(0)},#整个MongoDB实例的全局写锁
"timeAcquiringMicros" : {#为了获得锁,等待的微秒时间
"r" : NumberLong(16),#整个MongoDB实例的全局读锁
"w" : NumberLong(0)}#整个MongoDB实例的全局写锁