1. Analyze MongoDB Health with tool Mongostat
C:\users\administrator>mongostat--Help//View Support view live MongoDB performance Statistics.usage:mongostat [Options] [Sleep Time]Sleep Time: TimeTowait(inchseconds) between callsoptions:--Help produce Help message-V [--verbose] be Moreverbose (include multiple times for Moreverbosity e.g.-VVVVV)--quiet Silence all non error diagnostic messages --version Print the program's version and exit-h [--host] arg MONGO host to connect to (<Set name>/s1,s2 forsets)--port ARG server port. Can also use--Hosthostname:p Ort--IPv6 enable IPV6 support (disabled by default) -U [--Username] arg username-P [--Password] arg password--authenticationdatabase arg user source (defaults to dbname)--authenticationmechanism Arg (=mongodb-CR) authentication mechanism--gssapiservicename arg (=MongoDB) Service name to use when authenticating using GSSAPI/Kerberos--gssapihostname Arg Remote host name to use forPurpose of GSSAPI/Kerberos Authentication--noheaders Don't output column names-N [--rowcount] arg (=0) Number of stats lines to print (0 forindefinite)--HTTP Use HTTP instead of raw DB connection--discover discover nodes and display stats for All--All Optional fields inserts-# of inserts per second (*means replicated op) query-# of queries per second update-# of updates per second delete-# of Deletes per second Getmore-# of Get mores (cursor batch) per second command-# of commands per second, on a slave its local|Replicated Flushes-# of Fsync flushes per second mapped-amount of data mmaped (total data size) Megabytes Vsize-Virtual size of processinchMegabytes Res-Resident size of processinchMegabytes Non-mapped-amount Virtual Memeory LessMapped memory (with--All ) Faults-# of Pages faults per sec locked-Name of and percent Time forMost locked database idx Miss-percent of Btree page misses (sampled) QR|qw-queue Lengths forClients Waiting (read|Write) ar|aw-active Clients (read|Write) Netin-Network trafficinch-bytes Netout-Network traffic out-bytes Conn-Number of open connections set-replica set name Repl-Replication Type PRI-Primary (Master) SEC-Secondary REC-Recovering UNK-Unknown SLV-slave b RTR-MONGOs Process ("Router") C:\Users\Administrator>Mongostat connected to:127.0.0.1Insert Query Update delete getmore command flushes mapped vsize res faults locked db idx Miss% QR|QWar|AW Netin Netout Conn Time*0*0*0*0 0 1|0 0160m 446m 40m0Test0.0%0 0|0 0|062B 3k2 -: Wu:19
2.mongodb slow-Action log profile
> Db.getprofilinglevel ()//viewing slow logging Level 0 = off 1 = ALL operations over slowms 2 = record all lookups0> Db.setprofilinglevel (2){" was":0,"slowms": -,"OK":1}//Setting Logging Level 2> Show Tablessystem.profile//This is the log collection .> Db.system.profile.Find().Sort({$natural:-1}). Limit (1)//Natural Sort reverse View a log record {"op":"Query", "NS":"test.system.namespaces", "Query": { }, "Ntoreturn":0, "Ntoskip":0, "nscanned": One, "nscannedobjects": One, "keyupdates":0, "Numyield":0, "Lockstats": { "Timelockedmicros": { "R": Numberlong (177), "W": Numberlong (0) }, "Timeacquiringmicros": { "R": Numberlong (4), "W": Numberlong (4) } }, "nreturned": One, "ResponseLength":449, "Millis":0, "Execstats": { "type":"Collscan", "Works": -, "yields":0, "Unyields":0, "Invalidates":0, " Advanced": One, "Needtime":1, "Needfetch":0, "IsEOF":1, "docstested": One, "Children": [ ] }, "TS": Isodate ("2015-09-16t06:14:39.604z"), "Client":"127.0.0.1", "allUsers": [ ], "User":""}
The 3.explain method displays detailed information for the query statement
> db.system.local.Find(). Explain () {"cursor":"Basiccursor", "Ismultikey":false, "N":0, "nscannedobjects":0, "nscanned":0, "Nscannedobjectsallplans":0, "Nscannedallplans":0, "Scanandorder":false, "indexOnly":false, "Nyields":0, "nchunkskips":0, "Millis":0, "Server":"buexplain:27017"}
The state analysis of MongoDB