Mongodb_Monitor

1、wait lock

db.currentOp(   
   {    
     "waitingForLock" : true,    
     $or: [    
        { "op" : { "$in" : [ "insert", "update", "remove" ] } },    
        { "query.findandmodify": { $exists: true } }    
    ]    
   }    
)

2、cur_index

db.currentOp(   
    {    
      $or: [    
        { op: "command", "query.createIndexes": { $exists: true } },    
        { op: "insert", ns: /\.system\.indexes\b/ }    
      ]    
    }    
)

3、op_gte_2s

db.currentOp({"secs_running": {$gte: 2}});

4、op_collscan

db.currentOp({"planSummary" : "COLLSCAN"})

5、cur_ns_cnt

var s = db.currentOp();   db.cur_op_txt_cz.drop(); for(var i = 0; i<s.inprog.length;i++){       var ns_t = s.inprog[i].ns;              var ns_plan = s.inprog[i].planSummary; db.cur_op_txt_cz.insert({"ns_name":ns_t,"planSummary":ns_plan}) }; db.cur_op_txt_cz.aggregate([{$group : {_id : {ns_name:"$ns_name",planSummary:"$planSummary"}, cnt : {$sum : 1}}}]);

6、cur_collscan_op

 db.currentOp().inprog.forEach(function(item) { 
    if (item.planSummary == "COLLSCAN" && item.ns !== "local.oplog.rs") { 
        var tab_name = item["ns"]; 
        print("na_name:", tab_name, "  ", item.op, "  ", JSON.stringify(item.client_s), "  ", item.opid, "  ", JSON.stringify(item.query));  
    }
});

7、tab_for_kill

 db.currentOp().inprog.forEach(function(item) { 
    if (item.op == "query" && item.active && item.ns == "db_name.tb_name") { 
        { 
            print("kill_id: ", item.opid), 
            db.killOp(item.opid) 
        } 
    } 
});

8、mongostat

mongostat -h 92.12.76.13:27001 -u shard_admin -p 'shard_admin@!2020' --authenticationDatabase=admin --humanReadable=true --discover --all 2


db.test.update(
   {},
   {$set: { "customerAliasNames.$[element1].aliasName" : "abcc","customerAliasNames.$[element2].aliasName" : "deff"  } },
   
   {
     multi: true,
     arrayFilters: [ { "element1.aliasName": { $eq: "abc" } } ,
     { "element2.aliasName": { $eq: "def" } } ]
   }
)

10、碎片率

function getCollectionDiskSpaceFragRatio(dbname, coll) {
var res = db.getSiblingDB(dbname).runCommand({
collStats: coll
});
var totalStorageUnusedSize = 0;
var totalStorageSize = res['storageSize'] + res['totalIndexSize'];
Object.keys(res.indexDetails).forEach(function(key) {
var size = res['indexDetails'][key]['block-manager']['file bytes
available for reuse'];
print("index table " + key + " unused size: " +
size); totalStorageUnusedSize += size;
});
var size = res['wiredTiger']['block-manager']['file bytes available for reuse'];
print("collection table " + coll + " unused size: " + size);
totalStorageUnusedSize += size;
print("collection and index table total unused size: " +
totalStorageUnusedSize);
print("collection and index table total file size: " + totalStorageSize);
print("Fragmentation ratio: " + ((totalStorageUnusedSize * 100.0) /
totalStorageSize).toFixed(2) + "%");
12}
use xxxdb
db.getCollectionNames().forEach((c) => {print("\n\n" +
c); getCollectionDiskSpaceFragRatio(db.getName(),
c);});

--objectid时间查询

如何查找命令(此日期[2015-1-12]至此日期[2015-1-15]):
db.collection.find({_id:{$gt: ObjectId(Math.floor((new Date('2015/1/12'))/1000).toString(16) + "0000000000000000"), $lt: ObjectId(Math.floor((new Date('2015/1/15'))/1000).toString(16) + "0000000000000000")}}).pretty()
计算命令(此日期[2015-1-12]至此日期[2015-1-15]):
db.collection.count({_id:{$gt: ObjectId(Math.floor((new Date('2015/1/12'))/1000).toString(16) + "0000000000000000"), $lt: ObjectId(Math.floor((new Date('2015/1/15'))/1000).toString(16) + "0000000000000000")}})
删除命令(此日期[2015-1-12]至此日期[2015-1-15]):
db.collection.remove({_id:{$gt: ObjectId(Math.floor((new Date('2015/1/12'))/1000).toString(16) + "0000000000000000"), $lt: ObjectId(Math.floor((new Date('2015/1/15'))/1000).toString(16) + "0000000000000000")}})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值