# MongoDB Monitoring tools
## Run from the system cmd line
* Start/Stop/Restart MMS (Cloud Manager) agent service
``` sh
sudo systemctl start mongodb-mms-automation-agent.service
sudo systemctl stop mongodb-mms-automation-agent.service
sudo systemctl restart mongodb-mms-automation-agent.service
```
* List individual open connections
``` sh
$ sudo lsof -i | grep mongod
```
* mongotop provides a method to track the amount of time a MongoDB instance spends reading and writing data.
``` sh
mongotop --port 27017 -u "admin" -p "anORgdGl67mWJAowR6VqIfzdQi52AlbB" --authenticationDatabase "admin"
```
* mongostat provides a quick overview of the status of a currently running mongod or mongos instance.
``` sh
mongostat --port 27017 -u "admin" -p "anORgdGl67mWJAowR6VqIfzdQi52AlbB" --authenticationDatabase "admin"
```
* Check the number of client connections to MongoDB
``` sh
sudo lsof -i | grep mongod
```
_or_
``` sh
sudo lsof | grep mongod | grep TCP
```
## Run from the mongo shell *(Requires Admin access)*
* Returns a general overview of the status of the database
``` sh
vivo_01 PRIMARY> db.serverStatus()
```
* addresses storage use and data volumes
``` sh
vivo_01 PRIMARY> db.Stats()
```
* provides statistics that resemble dbStats on the collection level
``` sh
vivo_01 PRIMARY> db.collStats()
```
* returns an overview of your replica set’s status
``` sh
vivo_01 PRIMARY> db.replSetGetStatus()
```
* Check the number of client connections to MongoDB
``` sh
vivo_01 PRIMARY> db.serverStatus().connections
```
* View the Oplog size and duration
``` sh
vivo_01 PRIMARY> rs.printReplicationInfo()
```
* View replication lag info
``` sh
vivo_01 PRIMARY> rs.printSlaveReplicationInfo()
```