mongod經常使用操做命令

use notify_3077;
統計cmdb,monitor等以系統分組
db.op_log_201812.aggregate( [ { $group : { _id : "$system", count: {$sum: 1} } } ] )
 
use notify_1888;
db.op_log_ 201905.aggregate( [ {$match: {"system": "cmdb"}}, { $group : { _id : "$ext_info.object_id", count: {$sum: 1} } }, { $sort : { count : -1} } ] )
 
 
 統計大小
use cmdb_org_3077;
var collectionNames = db.getCollectionNames(), stats = [];
collectionNames.forEach(function (n) { stats.push(db[n].stats()); });
stats = stats.sort(function(a, b) { return b['size'] - a['size']; });
for (var c in stats) { print(stats[c]['ns'] + ": " + stats[c]['size'] + " (" + stats[c]['storageSize'] + ")"); }
 

經過查找一條,找具體字段,一個個往下找
db.op_log_201909.findOne()
db.op_log_201909.find({"system" : "cmdb"})
db.op_log_201909.find({"ext_info.object_name" : "虛擬機與工位機"})spa

db.op_log_201909.find({"ext_info.object_id":"HOST","system":"cmdb","ext_info.instance_id":"5c7cd381dedfa"})索引

db.log_instance201909.find({"_mac":"00:05:9A:3C:7A:00",_ts: {$gte: 1569554710,$lte: 1569557710}})get

統計總量
db.op_log_201909.count()
 
db.op_log_ 201909.aggregate( [ {$match: {"event": "event.instance.modify","ext_info.object_id":"HOST"}}, { $group : { _id : "$ext_info._change_fields", count: {$sum: 1} } }, { $sort : { count : -1} } ] )
 
db.op_log_ 201909.count({ $and: [ { ctime: { $gte: 1568044800, $lte: 1568683149 } }, { system: "cmdb" }, { $or: [ { target_id: "HOST" }, { target_category: "HOST" } ] }, { parent_event_id: { $in: [ null, "" ] } } ] } )
 

統計CMDB 模型變動記錄數
db.op_log_201909.aggregate( [ {$match: {"system": "cmdb"}}, { $group : { _id : "$ext_info.object_id", count: {$sum: 1} } }, { $sort : { count : -1} } ] )
統計上下線
db.op_log_201909.aggregate( [{$match: {"system":"monitor"}},{ $group : { _id : "$subject", count: {$sum: 1} } } ] )cmd

統計mac 一個時間段hostname變動虛擬機

db.log_instance201909.aggregate( [ {$match: {"_mac":"00:05:9A:3C:7A:00",_ts: {$gte: 1569554710}}}, { $group : { _id : "$hostname", count: {$sum: 1} } }, { $sort : { count : -1} } ] )
 

索引it

 db.op_log_ 201909.createIndex({"event_id":1,"system":1,"ctime":1,"target":1,"target_category":1})
 db.op_log_ 201909.dropIndex("event_id_1_system_1_ctime_1_target_1_target_category_1")
相關文章
相關標籤/搜索