centos7环境下使用python脚本监控mongodb集群复制状态
centos环境下搭建了 MongoDB 副本集,需要对集群的复制状态进行监控
获取集群的状态信息,集群是3个节点,没有设置仲裁者
[root@eus-image-design-mongo01:/usr/local]# mongo --port 21000MongoDB shell version v3.4.24connecting to: mongodb://127.0.0.1:21000/
MongoDB server version: 3.4.24configs:SECONDARY>use admin
switched to db admin
configs:SECONDARY> db.auth('zabbix','zabbix')1configs:SECONDARY>rs.status()
{"set" : "configs","date" : ISODate("2020-11-12T08:07:11.216Z"),"myState" : 2,"term" : NumberLong(4),"syncingTo" : "172.30.0.110:21000","syncSourceHost" : "172.30.0.110:21000","syncSourceId" : 2,"configsvr" : true,"heartbeatIntervalMillis" : NumberLong(2000),"optimes": {"lastCommittedOpTime": {"ts" : Timestamp(1605168428, 2),"t" : NumberLong(4)
},"readConcernMajorityOpTime": {"ts" : Timestamp(1605168428, 2),"t" : NumberLong(4)
},"appliedOpTime": {"ts" : Timestamp(1605168428, 2),"t" : NumberLong(4)
},"durableOpTime": {"ts" : Timestamp(1605168428, 2),"t" : NumberLong(4)
}
},"members": [
{"_id" : 0,"name" : "172.30.0.109:21000","health" : 1,"state" : 2,"stateStr" : "SECONDARY","uptime" : 8363759,"optime": {"ts" : Timestamp(1605168428, 2),"t" : NumberLong(4)
},"optimeDate" : ISODate("2020-11-12T08:07:08Z"),"syncingTo" : "172.30.0.110:21000","syncSourceHost