mongostat跟踪Mongodb运行的状态

版本控制

从 MongoDB 4.4 开始,mongostat 现在与 MongoDB 服务器分开发布,并使用自己的版本控制,初始版本为100.0.0. 之前,

mongostat 与 MongoDB Server 一起发布并使用匹配的版本控制。

兼容性

mongostat 版本100.7.3支持以下版本的 MongoDB Server:

MongoDB 6.0

MongoDB 5.0

MongoDB 4.4

MongoDB 4.2

mongostat 实用程序提供当前正在运行的mongod 或者 mongos 实例状态的概述 。

mongostat 功能上类似于 UNIX/Linux 文件系统实用程序vmstat。

访问权限

为了连接到 mongod 强制授权 --auth 选项,指定 --username 和--password选项,并且连接用户必须具有 serverStatus

对集群资源的特权操作。

内置角色 clusterMonitor 提供此特权以及其他特权。

shell 复制代码
sit_rs1:PRIMARY> db.getRole("clusterMonitor", { showPrivileges: true }).privileges[0]
{
       "resource" : {
               "cluster" : true
       },
       "actions" : [
               "checkFreeMonitoringStatus",
               "connPoolStats",
               "getDefaultRWConcern",
               "getCmdLineOpts",
               "getLog",
               "getParameter",
               "getShardMap",
               "hostInfo",
               "inprog",
               "listDatabases",
               "listSessions",
               "listShards",
               "netstat",
               "replSetGetConfig",
               "replSetGetStatus",
               "serverStatus",                #  ------>  serverStatus  特权  
               "shardingState",
               "top",                        
               "useUUID"
       ]
}

示例

--uri=<connectionString> 指定可解析的 URI 连接字符串 MongoDB 部署的信息,用引号引起来:

shell 复制代码
root@ubuntu-x64_01:/opt# mongostat 5 --uri='mongodb://admin:******@192.168.88.11:27018/admin?authSource=admin'  
2023-07-28T14:51:32.527+0800    WARNING: On some systems, a password provided directly in a connection string or using --uri may be visible to system status programs such as `ps` that may be invoked by other users. Consider omitting the password to provide it via stdin, or using the --config option to specify a configuration file with the password.
insert query update delete getmore command dirty used flushes vsize  res qrw arw net_in net_out conn     set repl                time
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   455b   10.9k    9 sit_rs1  SEC Jul 28 14:51:37.564
    *0    *0     *0     *0       0     2|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   437b   11.1k    9 sit_rs1  SEC Jul 28 14:51:42.563
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   456b   11.0k    9 sit_rs1  SEC Jul 28 14:51:47.565
    *0    *0     *0     *0       0     2|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   438b   11.1k    9 sit_rs1  SEC Jul 28 14:51:52.560
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   456b   11.0k    9 sit_rs1  SEC Jul 28 14:51:57.561
    *0    *0     *0     *0       0     2|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   437b   11.1k    9 sit_rs1  SEC Jul 28 14:52:02.560
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   456b   11.0k    9 sit_rs1  SEC Jul 28 14:52:07.562
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   398b   11.1k    9 sit_rs1  SEC Jul 28 14:52:12.564
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 105M 0|0 1|0   495b   11.0k    9 sit_rs1  SEC Jul 28 14:52:17.565
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       1 1.78G 105M 0|0 1|0   399b   10.9k    9 sit_rs1  SEC Jul 28 14:52:22.557

100.0从版本开始 mongostat ,连接字符串也可以作为位置参数提供,而不使用 --uri 选项:作为位置参数,可以在命令行上的任何点指定连接字符串,只要它以 mongodb:// 或 mongodb+srv:// 开头。例如:

shell 复制代码
root@ubuntu-x64_01:/opt# mongostat 5 --username admin --password ****** mongodb://192.168.88.11:27018 --authenticationDatabase=admin
2023-07-28T14:54:07.588+0800    WARNING: On some systems, a password provided directly using --password may be visible to system status programs such as `ps` that may be invoked by other users. Consider omitting the password to provide it via stdin, or using the --config option to specify a configuration file with the password.
insert query update delete getmore command dirty used flushes vsize  res qrw arw net_in net_out conn     set repl                time
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   415b   10.9k    9 sit_rs1  SEC Jul 28 14:54:12.614
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   478b   11.2k    9 sit_rs1  SEC Jul 28 14:54:17.612
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       1 1.78G 106M 0|0 1|0   416b   10.9k    9 sit_rs1  SEC Jul 28 14:54:22.614
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   438b   11.2k    9 sit_rs1  SEC Jul 28 14:54:27.612
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   455b   10.9k    9 sit_rs1  SEC Jul 28 14:54:32.616
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   439b   11.0k    9 sit_rs1  SEC Jul 28 14:54:37.608
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   455b   11.0k    9 sit_rs1  SEC Jul 28 14:54:42.616
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   439b   11.0k    9 sit_rs1  SEC Jul 28 14:54:47.610
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   455b   11.1k    9 sit_rs1  SEC Jul 28 14:54:52.615
    *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 106M 0|0 1|0   439b   11.0k    9 sit_rs1  SEC Jul 28 14:54:57.610

或者,您可以使用 --host 和 --port 指定主机和端口的选项:如果 mongod 实例需要认证,可以指定用户 -u,以及认证数据库 --authenticationDatabase。如果省略 --password 选项会提示输入密码。

shell 复制代码
root@ubuntu-x64_01:/opt# mongostat 5 --username=admin --password=****** --authenticationDatabase=admin --host=192.168.88.11 --port=27017 
2023-07-28T15:00:25.446+0800    WARNING: On some systems, a password provided directly using --password may be visible to system status programs such as `ps` that may be invoked by other users. Consider omitting the password to provide it via stdin, or using the --config option to specify a configuration file with the password.
insert query update delete getmore command dirty used flushes vsize  res qrw arw net_in net_out conn     set repl                time
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.43k   11.6k   17 sit_rs1  PRI Jul 28 15:00:30.478
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.01k   11.7k   17 sit_rs1  PRI Jul 28 15:00:35.472
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.63k   11.7k   17 sit_rs1  PRI Jul 28 15:00:40.470
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.01k   11.7k   17 sit_rs1  PRI Jul 28 15:00:45.469
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.43k   11.6k   17 sit_rs1  PRI Jul 28 15:00:50.474
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0   970b   11.5k   17 sit_rs1  PRI Jul 28 15:00:55.468
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.55k   11.9k   17 sit_rs1  PRI Jul 28 15:01:00.471
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0   970b   11.5k   17 sit_rs1  PRI Jul 28 15:01:05.469
    *0    *0     *0     *0       0     2|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  1.47k   11.8k   17 sit_rs1  PRI Jul 28 15:01:10.473
    *0    *0     *0     *0       1     4|0  0.0% 0.2%       0 1.83G 106M 0|0 1|0  2.98k   13.3k   17 sit_rs1  PRI Jul 28 15:01:15.468

连接到副本集或分片集群,使用 --discover 选项 发现并报告所有成员的统计数据 。

  • 在许多情况下,使用 --discover选项将有助于提供整个机器组状态的更完整的快照。如果连接到分片集群的mongos进程运行在本地机器的27017端口上,您可以使用以下表格返回集群所有成员的统计信息:
shell 复制代码
root@ubuntu-x64_01:/opt# mongostat 5 'mongodb://admin:******@192.168.88.11:27017,192.168.88.11:27018,192.168.88.11:27019/admin?authSource=admin&replicaSet=sit_rs1&readPreference=primary&ssl=false' --discover

               host insert query update delete getmore command dirty used flushes vsize  res qrw arw net_in net_out conn     set repl                time
192.168.88.11:27017     *0    *0     *0     *0       0     1|0  0.0% 0.2%       0 1.83G 107M 0|0 1|0   875b   11.1k   17 sit_rs1  PRI Jul 28 15:09:56.999
192.168.88.11:27018     *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 107M 0|0 1|0   395b   10.8k    9 sit_rs1  SEC Jul 28 15:09:57.017
192.168.88.11:27019     *0    *0     *0     *0       0     1|0  0.0% 0.4%       0 1.78G 116M 0|0 1|0   395b   10.8k   10 sit_rs1  SEC Jul 28 15:09:57.042

192.168.88.11:27017     *0    *0     *0     *0       0     3|0  0.0% 0.2%       0 1.83G 107M 0|0 1|0  1.57k   12.2k   17 sit_rs1  PRI Jul 28 15:10:01.990
192.168.88.11:27018     *0    *0     *0     *0       0     2|0  0.0% 0.3%       0 1.78G 107M 0|0 1|0   498b   11.2k    9 sit_rs1  SEC Jul 28 15:10:02.020
192.168.88.11:27019     *0    *0     *0     *0       0     2|0  0.0% 0.4%       0 1.78G 116M 0|0 1|0   539b   11.4k   10 sit_rs1  SEC Jul 28 15:10:02.036

192.168.88.11:27017     *0    *0     *0     *0       0     1|0  0.0% 0.2%       0 1.83G 107M 0|0 1|0   875b   11.1k   17 sit_rs1  PRI Jul 28 15:10:06.996
192.168.88.11:27018     *0    *0     *0     *0       0     1|0  0.0% 0.3%       0 1.78G 107M 0|0 1|0   396b   10.8k    9 sit_rs1  SEC Jul 28 15:10:07.019
192.168.88.11:27019     *0    *0     *0     *0       0     1|0  0.0% 0.4%       0 1.78G 116M 0|0 1|0   395b   10.8k   10 sit_rs1  SEC Jul 28 15:10:07.042

192.168.88.11:27017     *0    *0     *0     *0       0     3|0  0.0% 0.2%       0 1.83G 107M 0|0 1|0  1.53k   12.0k   17 sit_rs1  PRI Jul 28 15:10:11.996
192.168.88.11:27018     *0    *0     *0     *0       0     2|0  0.0% 0.3%       0 1.78G 107M 0|0 1|0   498b   11.2k    9 sit_rs1  SEC Jul 28 15:10:12.016
192.168.88.11:27019     *0    *0     *0     *0       0     2|0  0.0% 0.4%       0 1.78G 116M 0|0 1|0   538b   11.4k   10 sit_rs1  SEC Jul 28 15:10:12.044

在交互式界面中查看统计信息使用 --interactive 以非滚动方式查看统计信息的选项 风格的交互式输出。这 --interactive 选项允许您突出显示要查看的特定主机、列或字段。当与 --discover, --interactive 显示副本集或分片集群的所有成员的统计信息,如下例所示:

  • 退出: 'q' or <Esc>
  • 高亮:
    'v' 用于切换行
    'c' 用于切换列
    's' 用于切换单元格
    <Space> 清除所有高亮显示
  • 重绘: 'r'修复损坏的输出。
  • 箭头: 用定位行、列、单元格。
shell 复制代码
#
root@ubuntu-x64_01:/opt# mongostat 5 'mongodb://admin:******@192.168.88.11:27017,192.168.88.11:27018,192.168.88.11:27019/admin?authSource=admin&replicaSet=sit_rs1&readPreference=primary&ssl=false' --discover --interactive

               host insert query update delete getmore command dirty used flushes vsize  res qrw arw net_in net_out conn     set repl                time
192.168.88.11:27017     *0    *0     *0     *0       0     2|0  0.1% 0.3%       0 1.83G 107M 0|0 1|0  1.44k   11.9k   17 sit_rs1  PRI Jul 28 16:24:02.819
192.168.88.11:27018     *0    *0     *0     *0       0     1|0  0.1% 0.3%       0 1.79G 106M 0|0 1|0   398b   10.9k    9 sit_rs1  SEC Jul 28 16:24:02.829
192.168.88.11:27019     *0    *0     *0     *0       0     1|0  0.1% 0.4%       0 1.79G 102M 0|0 1|0   397b   10.9k   10 sit_rs1  SEC Jul 28 16:24:02.856

Press '?' to toggle help

-o 指定 mongostat 输出字段。您可以指定任何 serverStatus 作为 mongostat 输出列。

以下示例使用自定义字段 mongostat:

shell 复制代码
root@ubuntu-x64_01:/opt# mongostat 5 --username=admin --password=****** --authenticationDatabase=admin --host=192.168.88.11 --port=27017  -o='host,opcounters.insert.rate()=Insert Rate,opcounters.query.rate()=Query Rate,opcounters.command.rate()=Command Rate,wiredTiger.cache.pages requested from the cache=Pages Req,metrics.document.inserted=inserted rate'
               host Insert Rate Query Rate Command Rate Pages Req inserted rate
192.168.88.11:27017           0          0            1    101249             0
192.168.88.11:27017           0          0            2    101303             0
192.168.88.11:27017           0          0            1    101340             0
192.168.88.11:27017           0          0            2    101394             0
192.168.88.11:27017           0          0            2    101431             0
192.168.88.11:27017           0          0            2    101487             0
192.168.88.11:27017           0          0            2    101524             0
192.168.88.11:27017           0          0            2    101578             0
192.168.88.11:27017           0          0            2    101798             0



#  --discover --interactive   显示副本集或分片集群的所有成员的统计信息
root@ubuntu-x64_01:/opt# mongostat 5 'mongodb://admin:******@192.168.88.11:27017,192.168.88.11:27018,192.168.88.11:27019/admin?authSource=admin&replicaSet=sit_rs1&readPreference=primary&ssl=false'  -o='host,opcounters.insert.rate()=Insert Rate,opcounters.query.rate()=Query Rate,opcounters.command.rate()=Command Rate,wiredTiger.cache.pages requested from the cache=Pages Req,metrics.document.inserted=inserted rate'    --discover --interactive  

               host Insert Rate Query Rate Command Rate Pages Req inserted rate
192.168.88.11:27017           0          0            1    160296             0
192.168.88.11:27018           0          0            1    118386             0
192.168.88.11:27019           0          0            1    132224             0

Press '?' to toggle help
计算器 自定义字段名
opcounters.insert.rate 插入率
opcounters.query.rate 查询率
opcounters.command.rate 命令率
wiredTiger.cache.pages 页面请求
metrics.document.inserted 页面重新插入率

Fields

mongostat 返回反映 1 秒内操作的值。当mongostat <sleeptime> 的值大于 1 时,mongostat 对统计数据进行平均以反映每秒的平均操作数。mongostat 输出以下字段:

字段 描述
host 主机节点的IP地址
inserts 每秒插入数据库的对象数。如果后跟星号(例如*),则该数据指的是复制操作
query 每秒的查询操作数。
update 每秒更新操作的数量。
delete 每秒删除操作的数量。
getmore 每秒获取更多(即光标批处理)操作的数量。
command 每秒的命令数。在辅助系统上,mongostat 由管道字符分隔 表示两个值(例如:"
flushes 对于WiredTiger存储引擎,flushes 指的是每个轮询间隔之间触发的 WiredTiger 检查点的数量。
dirty 仅适用于WiredTiger存储引擎。WiredTiger 缓存中脏字节的百分比。
used 仅适用于WiredTiger存储引擎。正在使用的 WiredTiger 缓存的百分比。
vsize 在最后一次调用mongostat时,进程使用的虚拟内存量(以兆字节为单位)。
res 在最后一次调用mongostat时,进程使用的驻留内存量(以兆字节为单位)。
locked 全局写锁的时间百分比。仅在MongoDB实例的3.0之前版本上运行时出现。
qr 等待从 MongoDB 实例读取数据的客户端队列的长度。
qw 等待从 MongoDB 实例写入数据的客户端队列的长度。
ar 执行读取操作的活动客户端数量。
aw 执行写入操作的活动客户端数量。
netIn MongoDB 实例接收的网络流量(以字节为单位) 。这包括来自mongostat本身。
netOut MongoDB 实例发送的网络流量(以字节为单位) 。这包括来自mongostat本身。
conn 打开连接的总数。
set 副本集的名称(如果适用)。
repl 成员的复制状态。
相关推荐
hai4117419625 分钟前
mysql 与postgresql 的区别(gpt4)
数据库·mysql·postgresql
知识分享小能手15 分钟前
mysql学习教程,从入门到精通,SQL 删除数据(DELETE 语句)(19)
大数据·开发语言·数据库·sql·学习·mysql·数据开发
白总Server29 分钟前
MongoDB解说
开发语言·数据库·后端·mongodb·golang·rust·php
冰镇毛衣35 分钟前
2.4 数据库表字段约束
数据库·sql·mysql
&木头人&42 分钟前
oracle select字段有子查询会每次执行子查询吗
数据库·oracle
冰镇毛衣42 分钟前
数据库简介
开发语言·数据库·sql·oracle
(⊙o⊙)~哦43 分钟前
oracle查询历史操作记录
数据库·oracle
无休居士1 小时前
【实践】应用访问Redis突然超时怎么处理?
数据库·redis·缓存
M-bao1 小时前
缓存数据和数据库数据一致性问题
数据库·缓存
不二师妹1 小时前
硬盘数据恢复必备:4 款强大硬盘数据恢复软件推荐!
数据库·数据恢复·数据恢复软件·硬盘数据恢复·文件找回·恢复大师