mongdb系列之currentOp查找慢查询

currentOp

这个命令可以查看当前系统所有的操作信息,包括 find insert update remove等

db.currentOp(true)

{
	"host" : "mongodb:27018",
	"desc" : "conn71125",
	"connectionId" : 71125,
	"client" : "10.10.29.205:46144",
	"appName" : "mongoserver",
	"clientMetadata" : {
		"driver" : {
			"name" : "mongo-java-driver",
			"version" : "3.8.2"
		},
		"os" : {
			"type" : "Linux",
			"name" : "Linux",
			"architecture" : "amd64",
			"version" : "2.6.32-754.17.1.el6.x86_64"
		},
		"platform" : "Java/Oracle Corporation/1.8.0_181-b13",
		"application" : {
			"name" : "mongoserver"
		}
	},
	"active" : true,
	"currentOpTime" : "2020-06-02T15:10:56.411+0800",
	"opid" : 755826710,   当前操作的ID
	"secs_running" : NumberLong(23), 操作运行了多少秒
	"microsecs_running" : NumberLong(23086826),操作运行了多少微妙
	"op" : "query", 操作的类型是query
	"ns" : "md_index_test.crawlCommentDto", 操作的库名 表名
	"command" : { 查询语句的基本信息
		"find" : "crawlCommentDto",
		"filter" : {   过滤的条件 
			"type" : 3,
			"probability" : {
				"$gt" : -1
			},
			"brandId" : NumberLong(139)
		},
		"sort" : {
			"commentDate" : -1
		},
		"limit" : 4,
		"$db" : "md_index_test",
		"$readPreference" : {
			"mode" : "secondaryPreferred"
		}
	},
	"numYields" : 701,
	"locks" : { 锁的相关信息
		"Global" : "r",全局的读锁
		"Database" : "r", 库级别的读锁
		"Collection" : "r" 表级别的读锁
	},
	"waitingForLock" : false, 是否等待获取锁
	"lockStats" : {
		"Global" : {
			"acquireCount" : {
				"r" : NumberLong(1404)
			}
		},
		"Database" : {
			"acquireCount" : {
				"r" : NumberLong(702)
			}
		},
		"Collection" : {
			"acquireCount" : {
				"r" : NumberLong(702)
			}
		}
	}
}

打印客户端信息

    db.currentOp(true).inprog.forEach(    
        function(opDoc){    
            if (opDoc.client)    
        printjson(opDoc.client)    
        }    
    )

获取当前操作中已经停止的活动 并且操作行为是query

db.currentOp(true).inprog.forEach(
   function(opDoc){
     if(!opDoc.active && opDoc.op=='query')
        printjson(opDoc)
     }
 )
     

获取当前操作中已正在执行的活动 并且操作行为是query

 db.currentOp(true).inprog.forEach(
   function(opDoc){
     if(opDoc.active && opDoc.op=='query')
        printjson(opDoc)
     }
 )

db.killOp(opid) //kill当前的操作 opid为具体的操作id号,当然了,只能kill正在进行中的

  欢迎大家关注我的微信公众号 您的关注就是我不懈的动力 

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值