mongodb监控
使用Python去监控mongodb状态
获取mongodb的serverStatus状态信息,一般状态信息需要每个实例都进行监控
import pymongo client = pymongo.MongoClient('127.0.0.1',27017) db = client.admin serverStatus = db.command('serverStatus') print(serverStatus)
每个状态信息单独打印
import pymongo client = pymongo.MongoClient('127.0.0.1',27017) db = client.admin serverStatus = db.command('serverStatus') for key,value in serverStatus.items(): print(key, value) print()
MongoDB建议的监控方向
connections #连接信息
network #流量信息
opcounters #增删改查信息
状态信息获取
import pymongo client = pymongo.MongoClient('127.0.0.1',27017) db = client.admin serverStatus = db.command('serverStatus') print(serverStatus['connections']) print(serverStatus['network']) print(serverStatus['opcounters'])