一、mongostat定义

mongostat是MongoDB自带的性能分析工具,用于检测mongodb的运行状态。

Suwie/ # mongostat --help
Usage:
mongostat <options> <polling interval in seconds>
Monitor basic MongoDB server statistics.
See http://docs.mongodb.org/manual/reference/program/mongostat/ for more information.
general options:
--help print usage
--version print the tool version and exit
verbosity options:
-v, --verbose=<level> more detailed log output (include multiple times for more verbosity, e.g. -vvvvv, or specify a numeric value, e.g. --verbose=N)
--quiet hide all log output
connection options:
-h, --host=<hostname> mongodb host to connect to (setname/host1,host2 for replica sets)
--port=<port> server port (can also use --host hostname:port)
ssl options:
--ssl connect to a mongod or mongos that has ssl enabled
--sslCAFile=<filename> the .pem file containing the root certificate chain from the certificate authority
--sslPEMKeyFile=<filename> the .pem file containing the certificate and key
--sslPEMKeyPassword=<password> the password to decrypt the sslPEMKeyFile, if necessary
--sslCRLFile=<filename> the .pem file containing the certificate revocation list
--sslAllowInvalidCertificates bypass the validation for server certificates
--sslAllowInvalidHostnames bypass the validation for server name
--sslFIPSMode use FIPS mode of the installed openssl library
authentication options:
-u, --username=<username> username for authentication
-p, --password=<password> password for authentication
--authenticationDatabase=<database-name> database that holds the users credentials
--authenticationMechanism=<mechanism> authentication mechanism to use
stat options:
--noheaders dont output column names
-n, --rowcount=<count> number of stats lines to print (0 for indefinite)
--discover discover nodes and display stats for all
--http use HTTP instead of raw db connection
--all all optional fields
--json output as JSON rather than a formatted table

举例说明:
10秒数据,每2秒钟输出
mongostat -h 192.168.10.22 --port 27018 --rowcount 10 2
100秒数据,每5秒输出
mongostat -h 192.168.10.22 --port 27018 -n 100 5
以json格式输出
mongostat -h 192.168.10.22 --port 27018 -n 600 10 --json
输出如下:
MongoDB调优利器:掌握性能分析工具mongostat-LMLPHP

二 、输出详解

注1:正常情况mongostat输出used部分不建议超出80%,当内存used超过80%时,说明内存压力过大,进而会引起SQL查询性能下降。(现象:正常的SQL变成慢查询)这个时候,就需要考虑升级内存,缓解内存压力!

注2:dirty是cachesize里的脏页,写入量或者QPS比较高的情况,这个比例会增大。

其他说明:

  • q t|r|w #当Mongodb接收到太多的命令而数据库被锁住无法执行完成,它会将命令加入队列。这一栏显示了总共、读、写3个队列的长度,都为0的话表示mongo毫无压力。高并发时,一般队列值会升高。
  • qr #客户端等待从MongoDB实例读数据的队列长度
  • qw #客户端等待从MongoDB实例写入数据的队列长度
  • ar #执行读操作的活跃客户端数量
  • aw #执行写操作的活客户端数量
11-23 01:27