Olá,
O MongoDB possui função chamada db.currentOp() que retorna todas as
conexões abertas da instância. No comando abaixo irei retornar todas as
conexões que estão realizando operações que estão em execução a mais de 1
segundo. É possível verificar no exemplo abaixo que a conexão conn9145756
proveniente do servidor 192.168.1.10 está realizando uma query no banco bd01
e collection customer através do _id: ObjectId("0000001") com duração de
3 segundos. As demais operações estão ligadas ao namespace local.oplog.rs
que são operações de replicação do MongoDB.
mongoSet:PRIMARY> db.currentOp({"secs_running": {$gte: 1}})
{
"inprog" : [
{
"desc" : "conn9145756",
"threadId" : "139937773053696",
"connectionId" : 9145756,
"client" : "192.168.1.10:34456",
"active" : true,
"opid" : 425355448,
"secs_running" : 3,
"microsecs_running" : NumberLong(7491051),
"op" : "query",
"ns" : "bd01.customer",
"query" : {
"find" : "customer",
"filter" : {
"_id" : ObjectId("0000001")
},
"batchSize" : 300
},
"numYields" : 0,
"locks" : {
"Global" : "r",
"Database" : "r",
"Collection" : "r"
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
}
},
{
"desc" : "ReplBatcher",
"threadId" : "139937860310784",
"active" : true,
"opid" : 10,
"secs_running" : 1300926,
"microsecs_running" : NumberLong("22775762702217"),
"op" : "none",
"ns" : "local.oplog.rs",
"query" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"oplog" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
}
},
{
"desc" : "rsSync",
"threadId" : "139938179233536",
"active" : true,
"opid" : 9,
"secs_running" : 1300926,
"microsecs_running" : NumberLong("22775762702158"),
"op" : "none",
"ns" : "local.oplog.rs",
"query" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(24704),
"w" : NumberLong(18515),
"R" : NumberLong(6172),
"W" : NumberLong(6172)
},
"acquireWaitCount" : {
"W" : NumberLong(974)
},
"timeAcquiringMicros" : {
"W" : NumberLong(19504794)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(8),
"w" : NumberLong(1),
"W" : NumberLong(18514)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(7)
}
},
"Metadata" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"oplog" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
}
}
},
{
"desc" : "WT RecordStoreThread: local.oplog.rs",
"threadId" : "139938314262272",
"active" : true,
"opid" : 424925952,
"secs_running" : 920,
"microsecs_running" : NumberLong(920757610),
"op" : "none",
"ns" : "local.oplog.rs",
"query" : {
},
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(1),
"w" : NumberLong(1)
}
},
"Database" : {
"acquireCount" : {
"w" : NumberLong(1)
}
},
"oplog" : {
"acquireCount" : {
"w" : NumberLong(1)
}
}
}
}
],
"ok" : 1
}
Caso queiramos filtrar apenas as conexões ativas ignorando operações
internas de replicação, bastará utilizar o exemplo abaixo.
mongoSet:PRIMARY> db.currentOp({"active" : true,"secs_running" : { "$gt" : 0 },"ns" : {$ne : "local.oplog.rs"}})
{
"inprog" : [
{
"desc" : "conn1371708",
"threadId" : "140655653025536",
"connectionId" : 1371708,
"client" : "172.31.80.121:51282",
"active" : true,
"opid" : 2036637847,
"secs_running" : 1,
"microsecs_running" : NumberLong(1082772),
"op" : "query",
"ns" : "bd01.product",
"query" : {
"$msg" : "query not recording (too large)"
},
"numYields" : 58,
"locks" : {
"Global" : "r",
"Database" : "r"
},
"waitingForLock" : true,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(118)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(59)
},
"acquireWaitCount" : {
"r" : NumberLong(58)
},
"timeAcquiringMicros" : {
"r" : NumberLong(935638)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(58)
}
}
}
},
{
"desc" : "conn980301",
"threadId" : "140655740397312",
"connectionId" : 980301,
"client" : "192.168.1.10:55542",
"active" : true,
"opid" : 2036637676,
"secs_running" : 1,
"microsecs_running" : NumberLong(1310312),
"op" : "query",
"ns" : "bd01.product",
"query" : {
"$msg" : "query not recording (too large)"
},
"numYields" : 74,
"locks" : {
"Global" : "r",
"Database" : "r",
"Collection" : "r"
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(150)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(75)
},
"acquireWaitCount" : {
"r" : NumberLong(71)
},
"timeAcquiringMicros" : {
"r" : NumberLong(1140143)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(75)
}
}
}
},
{
"desc" : "conn980023",
"threadId" : "140655865579264",
"connectionId" : 980023,
"client" : "192.168.1.10:55132",
"active" : true,
"opid" : 2036637864,
"secs_running" : 1,
"microsecs_running" : NumberLong(1071661),
"op" : "query",
"ns" : "bd01.product",
"query" : {
"$msg" : "query not recording (too large)"
},
"numYields" : 63,
"locks" : {
"Global" : "r",
"Database" : "r"
},
"waitingForLock" : true,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(128)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(64)
},
"acquireWaitCount" : {
"r" : NumberLong(60)
},
"timeAcquiringMicros" : {
"r" : NumberLong(910226)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(63)
}
}
}
},
{
"desc" : "conn980300",
"threadId" : "140655781451520",
"connectionId" : 980300,
"client" : "192.168.1.10:44064",
"active" : true,
"opid" : 2036637740,
"secs_running" : 1,
"microsecs_running" : NumberLong(1200164),
"op" : "query",
"ns" : "bd01.product",
"query" : {
"$msg" : "query not recording (too large)"
},
"numYields" : 67,
"locks" : {
"Global" : "r",
"Database" : "r"
},
"waitingForLock" : true,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(136)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(68)
},
"acquireWaitCount" : {
"r" : NumberLong(64)
},
"timeAcquiringMicros" : {
"r" : NumberLong(1015696)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(67)
}
}
}
}
],
"ok" : 1
}
Nenhum comentário:
Postar um comentário