mongodb监控工具mongostat

mongostat是mongodb自带的状态检测工具,在命令行下使用,会间隔固定时间获取mongodb的当前运行状态,并输出。

mongostat查看帮助

$ 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(s) to connect to
                                                  (use commas to delimit hosts)
      --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
                                                  user's credentials
      --authenticationMechanism=<mechanism>       authentication mechanism to
                                                  use

uri options:
      --uri=mongodb-uri                           mongodb uri connection string

stat options:
  -o=<field>[,<field>]*                           fields to show. For custom
                                                  fields, use dot-syntax to
                                                  index into serverStatus
                                                  output, and optional methods
                                                  .diff() and .rate() e.g.
                                                  metrics.record.moves.diff()
  -O=<field>[,<field>]*                           like -o, but preloaded with
                                                  default fields. Specified
                                                  fields inserted after default
                                                  output
      --humanReadable=                            print sizes and time in human
                                                  readable format (e.g. 1K 234M
                                                  2G). To use the more precise
                                                  machine readable format, use
                                                  --humanReadable=false
                                                  (default: true)
      --noheaders                                 don't 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
      --useDeprecatedJsonKeys                     use old key names; only valid
                                                  with the json output option.
  -i, --interactive                               display stats in a
                                                  non-scrolling interface

参数说明

参数说明示例
-v详细的日志输出,包括更多的信息,v的数量可以有多个.mongostat -vvv --host 127.0.0.1:27017
-h要监控的数据库的ip和端口,可以写成-h或者 --host./mongostat -h 127.0.0.1:27017
-uadmin库的用户名,也可以写成 --username
-padmin库的密码,也可以写成 --password
--authenticationDatabase后面跟的是保存用户凭证的数据库,用户凭证在admin库中,所用这里填admin,这个参数是在有用户名和密码的时候才用的./mongostat -h 127.0.0.1:27017 -u root -p 123456 --authenticationDatabase admin
--noheaders不输出表头,就是没有最上面一行列的说明./mongostat -h 127.0.0.1:27017 --noheaders
-n要输出多少行,不指定默认一秒输出一行,指定以后,达到指定的行数以后就不在输出信息了,也可以写成--rowcount./mongostat -h 127.0.0.1:27017 -n 20
--discover监控所有节点并且显示./mongostat -h 127.0.0.1:27017 --discover
--http使用http链接,而不是原始的链接./mongostat -h 127.0.0.1:27017 --discover --http
--all所用可选的字段
--json打印的数据是json格式./mongostat -h 127.0.0.1:27017 --json

打印信息参数说明

参数说明
inserts/s每秒插入次数
query/s每秒查询次数
update/s每秒更新次数
delete/s每秒删除次数
getmore/s每秒执行getmore次数,查看更多的意思,我们每次查询数据时,如果一次数据量比较大,超过了mongodb一次能查询的最大数据量,那么mongodb就回把这次要查询的数据分成几次查询,分别返回
command/s每秒的命令数,比以上插入、查找、更新、删除的综合还多,还统计了别的命令
dirtyWiredTiger存储引擎中dirty 数据占缓存百分比
usedWiredTiger存储引擎中引擎使用缓存占百分比
flushes/s每秒执行fsync将数据写入硬盘的次数, WiredTiger存储引擎中,flushes是指WiredTiger循环创建检查点的时间间隔。每隔一段时间,mongodb就将内存上的数据写入硬盘,如果这个数值比较大的话,会影响性能
vsize虚拟内存使用量,单位MB
res物理内存使用量,单位MB
faults /s每秒访问失败数(只有Linux有),数据被交换出物理内存,放到swap。不要超过100,否则就是机器内存太小,造成频繁swap写入。此时要升级内存或者扩展
res使用真实内存大小
qr客户端等待读的长度,队列中的长度
qw客户端等待写的队列长度
ar活跃客户执行写操作的数量。
aw活跃客户等待写的数量
netinmongodb进入的流量包含mongostat本身(单位:bytes)
netoutmongodb出去的流量包含mongostat本身
conn当前连接数
time时间戳
repl当前实例的角色
M或 PRI"master",
SEC"Secondary",
REC"recovering",
UNK"unknow",
SLV"slave",
RTR"mongos process"("router")
ARB"arbiter"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
MongoDB性能监控可以使用mongotop和mongostat工具来实现。mongotop可以用于跟踪MongoDB实例在读写数据上所花费的时间,它提供了每个集合级别的统计信息。默认情况下,mongotop每秒返回一次值,可以使用命令"mongotop [frequency]"来控制频率,单位为秒。例如,使用命令"mongotop --authenticationDatabase admin -uroot -p123456 10",表示每隔10秒打印一次结果,其包括字段含义如下:ns表示命名空间,包含了数据库名字和集合名字;total表示在此命名空间上花费的总时间;read表示在此命名空间上执行读取操作花费的时间;write表示在此命名空间上执行写操作花费的时间。 另外,mongostat提供了对正在运行的MongoDB实例状态的快速概述,类似于UNIX/Linux的vmstat。它提供了关于mongod和mongos实例的数据。mongostat默认每1秒打印一次,可以在后面添加数字来改变打印频率。例如,使用命令"mongostat --authenticationDatabase admin -uroot -p123456 10",表示每隔10秒打印一次结果。mongostat返回1秒内操作的值,当mongostat的sleeptime值大于1时,它取平均值以反映每秒的平均数。 <span class="em">1</span><span class="em">2</span> #### 引用[.reference_title] - *1* *2* [MongoDB性能监控](https://blog.csdn.net/weixin_30895723/article/details/128038744)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

snipercai

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值