Get the App
SLTechnology News&Howtos  ›  Servers  › 

Monitoring of mongodb

Shulou Source: shulou.com Published: 2022-06-03 00:03:02 10月04日 Update

Monitoring ideas: one is the health status of cluster members, the other is the number of connections

1. Use the command rs.status () to improve the health of the members in the cluster.

MongoDB Enterprise config-rs:PRIMARY > rs.status () {"set": "config-rs", # replica set has been configured successfully "date": ISODate ("2019-11-23T04:56:35.588Z"), "myState": 1, "term": NumberLong (1), "syncingTo": "," syncSourceHost ":" "syncSourceId":-1, "configsvr": true, "heartbeatIntervalMillis": NumberLong (2000), "majorityVoteCount": 2, "writeMajorityCount": 2, "optimes": {lastCommittedOpTime: {"ts": Timestamp (1574484982, 1) "t": NumberLong (1)}, "lastCommittedWallTime": ISODate ("2019-11-23T04:56:22.464Z"), "readConcernMajorityOpTime": {"ts": Timestamp (1574484982, 1), "t": NumberLong (1)} ReadConcernMajorityWallTime: ISODate ("2019-11-23T04:56:22.464Z"), "appliedOpTime": {"ts": Timestamp (1574484982, 1), "t": NumberLong (1)} DurableOpTime: {"ts": Timestamp (1574484982, 1), "t": NumberLong (1)}, "lastAppliedWallTime": ISODate ("2019-11-23T04:56:22.464Z") LastDurableWallTime: ISODate ("2019-11-23T04:56:22.464Z")}, "lastStableRecoveryTimestamp": Timestamp (1574484952, 30), "lastStableCheckpointTimestamp": Timestamp (1574484952, 30), "electionCandidateMetrics": {"lastElectionReason": "electionTimeout", "lastElectionDate": ISODate ("2019-11-23T04:55:51.134Z") "termAtElection": NumberLong (1), "lastCommittedOpTimeAtElection": {"ts": Timestamp (0,0), "t": NumberLong (- 1)}, "lastSeenOpTimeAtElection": {"ts": Timestamp (1574484951, 1) "t": NumberLong (- 1), "numVotesNeeded": 1, "priorityAtElection": 1, "electionTimeoutMillis": NumberLong (10000), "newTermStartDate": ISODate ("2019-11-23T04:55:52.141Z") "wMajorityWriteAvailabilityDate": ISODate ("2019-11-23T04:55:52.266Z")}, "members": [{"_ id": 0, "name": "worker2:27018", "ip": "192.168.255.134" "health": 1, # Monitoring this value Alarm "state": 1, "stateStr": "PRIMARY", "uptime": 722, "optime": {"ts": Timestamp (1574484982, 1) "t": NumberLong (1)}, "optimeDate": ISODate ("2019-11-23T04:56:22Z"), "syncingTo": "," syncSourceHost ":" "syncSourceId": 1, "infoMessage": "could not find member to sync from", "electionTime": Timestamp (1574484951, 2), "electionDate": ISODate ("2019-11-23T04:55:51Z"), "configVersion": 2 "self": true, "lastHeartbeatMessage": ""}, {"_ id": 1, "name": "worker2:27019", "ip": "192.168.255.134" "health": 1, "state": 2, "stateStr": "SECONDARY", "uptime": 13, "optime": {"ts": Timestamp (1574484982) "t": NumberLong (1)}, "optimeDurable": {"ts": Timestamp (1574484982, 1), "t": NumberLong (1)} OptimeDate: ISODate ("2019-11-23T04:56:22Z"), "optimeDurableDate": ISODate ("2019-11-23T04:56:22Z"), "lastHeartbeat": ISODate ("2019-11-23T04:56:34.705Z"), "lastHeartbeatRecv": ISODate ("2019-11-23T04:56:35.176Z") "pingMs": NumberLong (0), "lastHeartbeatMessage": "," syncingTo ":", "syncSourceHost": "", "syncSourceId":-1, "infoMessage": "" "configVersion": 2}], "ok": 1, "$gleStats": {"lastOpTime": {"ts": Timestamp (1574484982, 1), "t": NumberLong (1)} "electionId": ObjectId ("7fffffff0000000000000001")}, "lastCommittedOpTime": Timestamp (1574484982, 1), "$clusterTime": {"clusterTime": Timestamp (1574484982,1), "signature": {"hash": BinData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA=") "keyId": NumberLong (0)}}, "operationTime": Timestamp (1574484982)}

Segmented description

Set

Current replica set name

Date

Time to execute the command

MyState

Status of the current node (role)

SyncingTo

Synchronous source

HeartbeatIntervalMillis

Heartbeat interval

Members

Node member

Members.id

Member number

Members.name

Member name

Members.heath

For health status, the value is monitored by 1mi true, 0m false. If 0 is combined with zabbix, the alarm will be given.

Members.state

Member status (role) 1-Primary Node 2-standby Node 7-Arbitration Node

Members.stateStr

Member status name

Members.uptime

Member startup run time

Members.optime

Member oplog timestamp (field ts)

Members.optimeDate

Member oplog time (formatted)

Members.lastHeartbeat

The last heartbeat of the current node to the member

Members.lastHeartbeatRecv

The current node receives the last heartbeat of the member

Members.pingMs

The length of the circuit from the current node to the member

Members.syncingTo

Member synchronization source

Members.electionTime

Primary node election timestamp (ms)

Members.electionDate

Primary node election time (formatted)

two。 Connect digital segments through mongostat monitoring conn

$mongostat-- host 192.168.255.134-- port 27017-u adminUser-p adminPass-- authenticationDatabase= "admin"-json {"192.168.255.134port 27017": {"arw": "1 | 0", "command": "2 | 0", "conn": "2", "delete": "* 0", "dirty": "0.0%", "flushes": "0", "getmore": "0", "insert": "* 0", "net_in": "167b" "net_out": "35.4k", "qrw": "0 | 0", "query": "* 0", "res": "83.0m", "time": "14:27:26", "update": "* 0", "used": "0.0%", "vsize": "1.52G"}}

3. You can introduce the pymongo module for monitoring, the specific script will not be posted, it is relatively simple. There is a problem if the number of connections is greater than 2000 by default. You can also use zabbix for custom monitoring. If the number of connections is greater than 2000, the alarm will be triggered. The monitoring script is python, which will be posted in a few days.

Tags: Members nodes monitoring time status health copy name command duration format script role cluster synchronization election success loop field idea Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn Docker MariaDB Xiaomi