mongostat跟踪Mongodb运行的状态

mongostat从4.4版开始独立发布,有自己独立的版本管理。它提供MongoDB服务器的状态概览,类似于vmstat。mongostat支持MongoDB6.0,5.0,4.4和4.2版本。连接到授权服务器需指定用户名、密码和具有serverStatus权限的角色,如clusterMonitor。mongostat可通过URI、位置参数或--host和--port选项连接,--discover选项用于显示副本集或分片集群所有成员的统计信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

版本控制

从 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 提供此特权以及其他特权。

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 部署的信息,用引号引起来:

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:// 开头。例如:

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 选项会提示输入密码。

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端口上,您可以使用以下表格返回集群所有成员的统计信息:
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’修复损坏的输出。
  • 箭头: 用定位行、列、单元格。
#
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:

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执行写入操作的活动客户端数量。
netInMongoDB 实例接收的网络流量(以字节为单位) 。这包括来自mongostat本身。
netOutMongoDB 实例发送的网络流量(以字节为单位) 。这包括来自mongostat本身。
conn打开连接的总数。
set副本集的名称(如果适用)。
repl成员的复制状态。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Ethanchen's notes

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

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

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

打赏作者

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

抵扣说明:

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

余额充值