I am using a db.currentOp() to check the current connection in Mongodb.
How can I get the total number of all record and how can I get all the "client" IP in a one column?
Thanks
db.currentOp()
{
"inprog" : [
{
"desc" : "WT RecordStoreThread: local.oplog.rs",
"threadId" : "1068",
"active" : true,
"opid" : 77300,
"secs_running" : 712,
"microsecs_running" : NumberLong(712734301),
"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)
}
}
}
},
{
"desc" : "conn52",
"threadId" : "4692",
"connectionId" : 52,
"client" : "10.10.50.218:60909",
"active" : true,
"opid" : 101277,
"secs_running" : 2,
"microsecs_running" : NumberLong(2883686),
"op" : "getmore",
"ns" : "local.oplog.rs",
"query" : {
"getMore" : NumberLong("15696192304"),
"collection" : "oplog.rs",
"maxTimeMS" : NumberLong(5000),
"term" : NumberLong(117),
"lastKnownCommittedOpTime" : {
"ts" : Timestamp(1501842736, 18),
"t" : NumberLong(117)
}
},
"planSummary" : "COLLSCAN",
"numYields" : 0,
"locks" : {
},
"waitingForLock" : false,
"lockStats" : {
"Global" : {
"acquireCount" : {
"r" : NumberLong(2)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(1)
}
},
"oplog" : {
"acquireCount" : {
"r" : NumberLong(1)
}
}
}
},
....
...
..
Best Answer
This will help to aggregate the information -
Connection Count by ClientIP, with Total
For Mongo Shell:
Formatted:
Example Output:
(the 192.x.x.x addresses are internal Atlas monitoring)