1.借助工具 mongostat 分析mongodb运行状况
C:\Users\Administrator>mongostat --help //查看帮助
View live MongoDB performance statistics.
usage: mongostat [options] [sleep time]
sleep time: time to wait (in seconds) between calls
Options:
--help produce help message
-v [ --verbose ] be more verbose (include multiple times
for more verbosity 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 (
--port arg server port. Can also use --host
hostname:port
--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 for purpose of
GSSAPI/Kerberos authentication
--noheaders don't output column names
-n [ --rowcount ] arg (=) number of stats lines to print ( for
indefinite)
--http use http instead of raw db connection
--discover discover nodes and display stats for
all
--all all optional fields
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 process in megabytes
res - resident size of process in megabytes
non-mapped - amount virtual memeory less mapped memory (only with --all)
faults - # of pages faults per sec
locked - name of and percent time for most locked database
idx miss - percent of btree page misses (sampled)
qr|qw - queue lengths for clients waiting (read|write)
ar|aw - active clients (read|write)
netIn - network traffic in - 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.1
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
* * * * | 160m 446m 40m test:0.0% | | 62b 3k ::19
2.mongodb慢操作日志 profile
> db.getProfilingLevel() //查看慢日志记录级别 0=关闭 1=所有超过slowms的操作 2=记录所有查找
db.setProfilingLevel(){ "was" : , "slowms" : , "ok" : } //设置日志记录级别2
show tablessystem.profile //这个就是日志集合
db.system.profile.find().sort({$natural:-}).limit() //自然排序 倒序查看一条日志记录
{
"op": "query",
"ns": "test.system.namespaces",
"query": {
},
"ntoreturn": ,
"ntoskip": ,
"nscanned": ,
"nscannedObjects": ,
"keyUpdates": ,
"numYield": ,
"lockStats": {
"timeLockedMicros": {
"r": NumberLong(),
"w": NumberLong()
},
"timeAcquiringMicros": {
"r": NumberLong(),
"w": NumberLong()
}
},
"nreturned": ,
"responseLength": ,
"millis": ,
"execStats": {
"type": "COLLSCAN",
"works": ,
"yields": ,
"unyields": ,
"invalidates": ,
"advanced": ,
"needTime": ,
"needFetch": ,
"isEOF": ,
"docsTested": ,
"children": \[
\]
},
"ts": ISODate("2015-09-16T06:14:39.604Z"),
"client": "127.0.0.1",
"allUsers": \[
\],
"user": ""
}
3.explain 方法显示查询语句的详细信息
> db.system.local.find().explain()
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : ,
"nscannedObjects" : ,
"nscanned" : ,
"nscannedObjectsAllPlans" : ,
"nscannedAllPlans" : ,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : ,
"nChunkSkips" : ,
"millis" : ,
"server" : "buexplain:27017"
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章