目录:
MongoDB学习笔记(一)环境搭建与常用操作
MongoDB学习笔记(二)使用Java操作MongoDB
MongoDB学习笔记(三)使用Spring Data操作MongoDB
MongoDB学习笔记(四)使用Java进行实时监控与数据收集
最近在做一个Java开发的监控系统,里面有一个模块是监控MongoDB的。看到网络上比较少这块资料,特记录如下:
1.下载MongoDB的Java驱动包。
2.获取空间使用量等数据:
CommandResult stats=db.getStats();
获取到的数据如下:
{
"serverUsed": "172.1.1.3:15080",
"db": "monitor",
"collections": 27,
"objects": 26358,
"avgObjSize": 1044.4045830487898,
"dataSize": 27528416,
"storageSize": 53030912,
"numExtents": 73,
"indexes": 25,
"indexSize": 1062880,
"fileSize": 1006632960,
"nsSizeMB": 16,
"dataFileVersion": {
"major": 4,
"minor": 5
},
"extentFreeList": {
"num": 71,
"totalSize": 654319616
},
"ok": 1.0
}
3.获取连接数等数据:
CommandResult stats=db.command("serverStatus");
获取到的数据如下:
{
"serverUsed": "172.1.1.3:15080",
"host": "docker:80",
"version": "2.6.6",
"process": "mongod",
"pid": 49,
"uptime": 687177.0,
"uptimeMillis": 687177657,
"uptimeEstimate": 679910.0,
"localTime": {
"$date": "2016-03-08T16:15:46.815Z"
},
"asserts": {
"regular": 1,
"warning": 1,
"msg": 0,
"user": 58812,
"rollovers": 0
},
"backgroundFlushing": {
"flushes": 11452,
"total_ms": 143088,
"average_ms": 12.494586098498079,
"last_ms": 78,
"last_finished": {
"$date": "2016-03-08T16:14:50.610Z"
}
},
"connections": {
"current": 13,
"available": 806,
"totalCreated": 1794
},
"cursors": {
"note": "deprecated, use server status metrics",
"clientCursors_size": 0,
"totalOpen": 0,
"pinned": 0,
"totalNoTimeout": 38,
"timedOut": 3
},
"dur": {
"commits": 29,
"journaledMB": 0.008192,
"writeToDataFilesMB": 0.003634,
"compression": 2.0262181548355183,
"commitsInWriteLock": 0,
"earlyCommits": 0,
"timeMs": {
"dt": 3009,
"prepLogBuffer": 0,
"writeToJournal": 40,
"writeToDataFiles": 0,
"remapPrivateView": 0
}
},
"extra_info": {
"note": "fields vary by platform",
"heap_usage_bytes": 67277952,
"page_faults": 692
},
"globalLock": {
"totalTime": 687177659000,
"lockTime": 47304462,
"currentQueue": {
"total": 0,
"readers": 0,
"writers": 0
},
"activeClients": {
"total": 0,
"readers": 0,
"writers": 0
}
},
"indexCounters": {
"accesses": 431329,
"hits": 431329,
"misses": 0,
"resets": 0,
"missRatio": 0.0
},
"locks": {
".": {
"timeLockedMicros": {
"R": 9599442,
"W": 47304462
},
"timeAcquiringMicros": {
"R": 4543336,
"W": 1125820
}
},
"admin": {
"timeLockedMicros": {
"r": 2625360,
"w": 0
},
"timeAcquiringMicros": {
"r": 158482,
"w": 0
}
}
},
"network": {
"bytesIn": 96033519,
"bytesOut": 177762851,
"numRequests": 878581
},
"opcounters": {
"insert": 108167,
"query": 262770,
"update": 1014,
"delete": 6,
"getmore": 50,
"command": 632623
},
"opcountersRepl": {
"insert": 0,
"query": 0,
"update": 0,
"delete": 0,
"getmore": 0,
"command": 0
},
"recordStats": {
"accessesNotInMemory": 2,
"pageFaultExceptionsThrown": 1,
"admin": {
"accessesNotInMemory": 0,
"pageFaultExceptionsThrown": 0
}
},
"writeBacksQueued": false,
"mem": {
"bits": 64,
"resident": 196,
"virtual": 4782,
"supported": true,
"mapped": 2000,
"mappedWithJournal": 4000
},
"metrics": {
"cursor": {
"timedOut": 3,
"open": {
"noTimeout": 38,
"pinned": 0,
"total": 0
}
},
"document": {
"deleted": 21,
"inserted": 78767,
"returned": 103245,
"updated": 1014
},
"getLastError": {
"wtime": {
"num": 0,
"totalMillis": 0
},
"wtimeouts": 0
},
"operation": {
"fastmod": 1,
"idhack": 0,
"scanAndOrder": 0
},
"queryExecutor": {
"scanned": 0,
"scannedObjects": 0
},
"record": {
"moves": 0
},
"repl": {
"apply": {
"batches": {
"num": 0,
"totalMillis": 0 },
"ops": 0
},
"buffer": {
"count": 0,
"maxSizeBytes": 268435456,
"sizeBytes": 0
},
"network": {
"bytes": 0,
"getmores": {
"num": 0,
"totalMillis": 0 },
"ops": 0,
"readersCreated": 0
},
"preload": {
"docs": {
"num": 0,
"totalMillis": 0 },
"indexes": {
"num": 0,
"totalMillis": 0 }
}
},
"storage": {
"freelist": {
"search": {
"bucketExhausted": 0,
"requests": 130732,
"scanned": 231145 }
}
},
"ttl": {
"deletedDocuments": 0,
"passes": 11452
}
},
"ok": 1.0
}