# MongoDB Diagnostics and Debugging (Version 3.4) <br />ch2 Tooling Overview
###### tags: `MongoDB University M312`
## Introduction to Diagnostic and Debugging Tools
### MongoDB tools
* mongostat - shows incoming operation in real time.
* mongotop - to know which collection we're spending time reading from and writing to.
* mongoreplay - to monitor record and replay network traffic
* mongo
* profiler - logs queries
* compass
* mtools
## Introducing Server Logs
### Server Log Components
* ACCESS
* COMMAND
* CONTROL
* GEO
* INDEX
* NETWORK
* QUERY
* REPL
* SHARDING
* STORAGE
* JOURNAL
* WRITE
### Level Description
**F** fatal
**E** error
**W** warning
**I** information, for Verbosity Levels of 0
**D** Debug, for All Verbosity Levels >
You can always run your system with maximum verbosity, if you wanted to capture more infomation.
```javascript=
mongod -vvvvv
```
## currentOp and killOp
* currentOp - Shows what the server doing, the current operation
```javascript=
db.currentOp()
```
* killOp - To kill a operation
```javascript=
db.killOp(<opID>)
```
## Introducing Server Status
#### db.serverStatus()
Although ***db.serverStatus()*** gives us a huge information, the output can be grouped into a few different sections.
### List of Topics
* Instance Information
* Asserts
* Connections and Network
* Locking
* Operation stats
* Security
* Replication stats
* Storage Engine stats
* Metrics
***We can do the projection of output like this***
```javascript=
db.runCommand( { serverStatus: 1, repl: 0, metrix: 0, lock: 1, wireTiger: 0} )
```
To check key of the command by js function
```javascript=
Object.keys(serverStatus())
```
The output example of serverStatus
```javascript=
// operation counter
db.serverStatus().opcounters.insert
db.serverStatus().opcounterRepl
// host name
db.serverStatus().host
// version number
db.serverStatus().version
// process mongod or mongos
db.serverStatus().process
// process id
db.serverStatus().pid
// how long server is running
db.serverStatus().uptime
db.serverStatus().uptimeMillis
// local time
db.serverStatus().localtime
// current establish connection
db.serverStatus().connections
// assertion errors raised since the server process started
db.serverStatus().asserts
// operation latency
db.serverStatus().opLatencies
```
## Introducing the Profiler
Turnning profiler on, every operation comming in will be stored in **system.profile** collection.
The collection size is 1 megabyte by default and is a capped collection.
It's better to turn off if there was no special needs.
```javascript=
// show the profiler level
db.getProfilingLevel()
// set profiler level
db.setProfilingLevel()
```
level:
0: not capture any query
1: capture queries that take longer than 100ms
2: capture all queries
## Server Diagnostic Tools
* bsondump
* mongo
* mongod
* mongodecrypt
* mongodump
* mongoexport
* mongofiles
* mongoimport
* ==mongoldap==
* mongooplog
* ==mongoperf==
* ==mongoreplay==
* mongorestore
* mongos
* ==mongostat==
* ==mongotop==
## $indexStats
We can get the usage frequency by using the aggreation.
[DOC](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/)