mongostat跟踪Mongodb运行的状态

这篇具有很好参考价值的文章主要介绍了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 提供此特权以及其他特权。

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 输出以下字段:文章来源地址https://www.toymoban.com/news/detail-617733.html

字段 描述
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 成员的复制状态。

到了这里,关于mongostat跟踪Mongodb运行的状态的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • [虚幻引擎 MongoDB Client 插件说明] DTMongoDB MongoDB数据库连接插件,UE蓝图可以操作MongoDB数据库增删改查。

    本插件可以在UE里面使用蓝图操作MongoDB数据库, 对数据库进行查询,删除,插入,替换,更新操作。 插件下载地址在文章最后。 Create MongoDB Client - 创建客户端对象 创建一个 MongoDB 客户端对象。 Connect By Url - 连接到数据库 Url :MongoDB的连接地址。 如 mongoDB://account:password@ip:

    2024年02月14日
    浏览(77)
  • 〖Python 数据库开发实战 - MongoDB篇⑧〗- MongoDB的数据结构

    订阅 Python全栈白宝书-零基础入门篇 可报销! 白嫖入口-请点击我。 推荐他人订阅,可获取扣除平台费用后的35%收益,文末名片加V! 说明:该文属于 Python全栈白宝书专栏, 免费阶段订阅数量4300+ , 购买任意白宝书体系化专栏可加入 TFS-CLUB 私域社区。 福利:加入社区的小伙

    2023年04月09日
    浏览(47)
  • MongoDB数据库从入门到精通系列文章之:MongoDB数据库百篇技术文章汇总

    MongoDB数据库系列文章持续更新中: 更多数据库内容请阅读博主数据库专栏,数据库专栏涵盖了Mysql、SQLServer、PostgreSQL、MongoDB、Oracle、Cassandra等数据库 数据库专栏 文章名称 文章链接 数据库安装部署系列之:部署Mongodb5.0.6高可用集群详细步骤 数据库安装部署系列之:部署M

    2024年02月11日
    浏览(43)
  • Mongodb连接数据库

    npm init   npm i mongoose  const mongoose=require(\\\"mongoose\\\") mongoose.connect(\\\"mongodb://127.0.0.1:27017/user\\\") 说明:mongodb是协议,user是数据库,如果没有会自动创建user数据库 。 node 文件名     mongoose.disconnect()

    2024年02月15日
    浏览(47)
  • MongoDB数据库安装

    MongoDB数据的特点: 面相文档存储的分布式数据库 具有很强的扩展性 支持丰富的查询表达式,很接近于关系性数据库 使用类似于json的结构保存数据,可以轻易的查询到文档中内嵌的对象及数组 首先去官网下载安装包 Download MongoDB Community Server | MongoDB 启动MongoDB数据的服务 可

    2024年02月11日
    浏览(47)
  • MongoDb数据库

    1.显示所有数据库: show dbs 2.切换到指定数据库,如果没有则自动创建数据库 use databaseName 3.显示当前所在数据库 db 4.删除当前数据库 use 库名 db.dropDatabase() 1.创建集合 db.createCollection(\\\'集合名称\\\') 2.显示当前数据库中所有集合 show colletions  3.删除某个集合 db.xxx.drop(); 4.重命名集

    2024年02月04日
    浏览(44)
  • mongodb数据库操作

    1、启动mongodb 在mongodb启动命令中 --dbpath 指定mongodb的数据存储路径 --logpath 指定mongodb的日志存储路径 2、停止mongodb 第一步先进入mongo命令行模式 第二步,使用use admin 命令进入admin数据库 第三步,执行 db.shutdownServer()命令 停止服务。代码及显示如下:  2 、导出Mongodb数据 mon

    2024年02月09日
    浏览(39)
  • 关系型非关系型数据库区别,以MongoDB为例在express中连接MongoDB示例

    目录 关系型数据库 关系型数据库常见的类型有: 关系型数据库的优点包括: 非关系型数据库 非关系型数据库常见的类型有: 非关系型数据库的特点包括: 关系型数据库和非关系型数据库区别 MongoDB是什么 MongoDB优势: 在Express中连接MongoDB步骤 Schema 关系型数据库是以关系模

    2024年01月16日
    浏览(62)
  • MongoDB:数据库初步应用

    1.MongoDBCompass连接数据库 连接路径:mongodb://用户名:密码@localhost:27017/ 2.创建数据库(集合) MongoDB中数据库被称为集合.  MongoDBCompass连接后,点击红色框加号创建集合,点击蓝色框加号创建文档(数据表) 文档中的数据结构(相当于表中的列)设计不用管,添加数据的时候,自动创建列和数

    2024年02月12日
    浏览(35)
  • python数据库——Mongodb

    MongoDB 是一个开源的 NoSQL数据库系统,它是一个面向文档的数据库,使用 JSON 格式来存储和查询数据。MongoDB 是一个非关系型数据库,它的设计目标是以高性能、高可用性和可扩展性为特点,适用于处理大量的非结构化数据。 特点: MongoDB 是一个面向文档存储的数据库,操作

    2024年02月07日
    浏览(33)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包