Created
February 1, 2019 17:08
-
-
Save HugoPoi/93c069272a01ba75d6fd34ae332083d6 to your computer and use it in GitHub Desktop.
MongoDB get estimate oplog per collection with profiler
This file contains hidden or 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
// https://docs.mongodb.com/manual/tutorial/manage-the-database-profiler/#enable-and-configure-database-profiling | |
(() => { | |
return db.system.profile.aggregate([ | |
{ $match: { $or: [{op: {$in: ['update', 'insert', 'delete']}}, {'command.writeConcern': {$exists: true}}] } }, | |
{ $group: {_id: {op : '$op', ns: '$ns', client: "$client"}, count: {$sum: 1}, start: {$min: "$ts"}, end: {$max: "$ts"} } }, | |
{ $match: { count: { $gt: 50}}}, | |
{ $sort: {count: -1} } | |
]).map((requestStats) => { | |
let stats = db.getCollection(requestStats._id.ns.split('.')[1]).stats(); | |
requestStats.queryPerHour = ( 3600000 / (requestStats.end - requestStats.start) ) * requestStats.count; | |
requestStats.estimateOpLogPerHour = stats.avgObjSize * requestStats.queryPerHour; | |
requestStats.estimateOpLogPerHourMB = requestStats.estimateOpLogPerHour / ( 1024 * 1024 ); | |
return requestStats; | |
}) | |
//.reduce((acc,e) => e.estimateOpLogPerHourMB + acc, 0); | |
.sort((a,b) => b.estimateOpLogPerHourMB - a.estimateOpLogPerHourMB); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment