Last active
January 28, 2019 09:45
-
-
Save nirebu/d6fda7dc8e9e34de8587cb6cd20ef156 to your computer and use it in GitHub Desktop.
[Mongo DB long queries aggregation] Aggregate for queries running on shards to detect if there are too many or too long queries slowing the system down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use admin | |
var threshold = 500; | |
db.aggregate([ | |
{ $currentOp : { allUsers: true } }, | |
{ $match: { "secs_running" : { $gt: threshold } , "ns" : { $not : /oplog/ } } }, | |
{ $group : { | |
_id: '$shard', | |
"n_query": { $sum: 1 }, | |
"avg_secs_running": { $avg: '$secs_running' } | |
,"operations" : { $push : { "opid" : '$opid' , "secs_running" : '$secs_running' } } | |
} | |
}, | |
{ $sort : { "n_query": 1 } } | |
]).pretty() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment