Mongodb监控命令
admin
2023-04-11 22:03:48
0

Mongodb监控命令


一、监控工具

1、mongostat工具

默认为显示每秒的统计信息

# mongostat -uroot -ppassword --authenticationDatabase admin -h292.168.x.xx  --rowcount 10 1
connected to: 192.168.x.xx
insert  query update delete getmore command flushes mapped  vsize    res faults  locked db idx miss %     qr|qw   ar|aw  netIn netOut  conn set repl       time 
    *0     *0     *0     *0       0     3|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0   178b     4k     6 rs0  SEC   21:02:36 
    *0     *0     *0     *0       0     3|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0   342b     4k     6 rs0  SEC   21:02:37 
    *0     *0     *0     *0       0     1|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0    62b     3k     6 rs0  SEC   21:02:38 
    *0     *0     *0     *0       0     3|0       1  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0   342b     4k     6 rs0  SEC   21:02:39 
    *0      6     *0     *0       0     1|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0    62b     3k     6 rs0  SEC   21:02:40 
    *0     *0     *0     *0       0     3|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0   342b     4k     6 rs0  SEC   21:02:41 
    *0     *0     *0     *0       0     1|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0    62b     3k     6 rs0  SEC   21:02:42 
    *0     *0     *0     *0       0     3|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0   342b     4k     6 rs0  SEC   21:02:43 
    *0     *0     *0     *0       0     1|0       0  1.19g  3.07g    85m      0  test:0.0%          0       0|0     0|0    62b     3k     6 rs0  SEC   21:02:44 
    *0     *0     *0     *0       0     3|0       0  1.19g  3.07g    85m      0   db4:0.0%          0       0|0     0|0   342b     4k     6 rs0  SEC   21:02:45

可以添加 --discover显示shard集群(连接mongos)和副本集的所有成员的统计信息。


输出含义,参考:http://docs.mongodb.org/v2.6/reference/program/mongostat/


2、mongotop工具

显示每个数据库的集合的读写时间,或每个数据库的读写锁时间(--locks),默认为1秒。

# mongotop -uroot -ppassword --authenticationDatabase admin -h292.168.x.xx  5
connected to: 192.168.x.xx

                            ns       total        read       write		2015-06-10T13:23:51
            db4.system.indexes         0ms         0ms         0ms
                      db4.$cmd         0ms         0ms         0ms
         db2.system.namespaces         0ms         0ms         0ms
            db2.system.indexes         0ms         0ms         0ms
                      db2.post         0ms         0ms         0ms
                    db1.userX2         0ms         0ms         0ms
                    db1.userX1         0ms         0ms         0ms

                            ns       total        read       write		2015-06-10T13:23:56
            db4.system.indexes         0ms         0ms         0ms
                      db4.$cmd         0ms         0ms         0ms
         db2.system.namespaces         0ms         0ms         0ms
            db2.system.indexes         0ms         0ms         0ms
                      db2.post         0ms         0ms         0ms
                    db1.userX2         0ms         0ms         0ms
                    db1.userX1         0ms         0ms         0ms

					
# mongotop -uroot -ppassword --authenticationDatabase admin -h292.168.x.xx  5 --locks
connected to: 192.168.x.xx

                            db       total        read       write		2015-06-10T13:24:42
                             .         1ms         1ms         0ms
                          test         0ms         0ms         0ms
                         local         0ms         0ms         0ms
                           db4         0ms         0ms         0ms
                           db2         0ms         0ms         0ms
                           db1         0ms         0ms         0ms
                         admin         0ms         0ms         0ms

                            db       total        read       write		2015-06-10T13:24:47
                          test         0ms         0ms         0ms
                         local         0ms         0ms         0ms
                           db4         0ms         0ms         0ms
                           db2         0ms         0ms         0ms
                           db1         0ms         0ms         0ms
                         admin         0ms         0ms         0ms
                             .         0ms         0ms         0ms	

输出含义,参考:http://docs.mongodb.org/v2.6/reference/program/mongotop/


3、db.serverStatus()

参考:http://docs.mongodb.org/v2.6/reference/command/serverStatus/


4、db.stats() 

> db.stats()
{
	"db" : "db4",
	"collections" : 3,
	"objects" : 13,
	"avgObjSize" : 87.38461538461539,
	"dataSize" : 1136,
	"storageSize" : 24576,
	"numExtents" : 3,
	"indexes" : 3,
	"indexSize" : 24528,
	"fileSize" : 16777216,
	"nsSizeMB" : 16,
	"dataFileVersion" : {
		"major" : 4,
		"minor" : 5
	},
	"extentFreeList" : {
		"num" : 0,
		"totalSize" : 0
	},
	"ok" : 1
}

参考:http://docs.mongodb.org/v2.6/reference/command/dbStats/#dbcmd.dbStats


5、db.collect_name.stats()

{
	"ns" : "db4.userInfo",
	"count" : 5,
	"size" : 560,
	"avgObjSize" : 112,
	"storageSize" : 8192,
	"numExtents" : 1,
	"nindexes" : 3,
	"lastExtentSize" : 8192,
	"paddingFactor" : 1,
	"systemFlags" : 1,
	"userFlags" : 1,
	"totalIndexSize" : 24528,
	"indexSizes" : {
		"_id_" : 8176,
		"name_hashed" : 8176,
		"age_1" : 8176
	},
	"ok" : 1
}

参考:http://docs.mongodb.org/v2.6/reference/command/collStats/#dbcmd.collStats


6、rs.status()

查询副本集信息

> rs.status()
{
	"set" : "rs0",
	"date" : ISODate("2015-06-11T04:02:55Z"),
	"myState" : 2,
	"syncingTo" : "192.168.x.xx:27018",
	"members" : [
		{
			"_id" : 0,
			"name" : "192.168.x.xx:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 84674,
			"optime" : Timestamp(1435989328, 1),
			"optimeDate" : ISODate("2015-07-04T05:55:28Z"),
			"lastHeartbeat" : ISODate("2015-06-11T04:02:54Z"),
			"lastHeartbeatRecv" : ISODate("2015-06-11T04:02:54Z"),
			"pingMs" : 8,
			"syncingTo" : "192.168.x.xx:27018"
		},
		{
			"_id" : 3,
			"name" : "192.168.x.xx:27017",
			"health" : 1,
			"state" : 2,
			"stateStr" : "SECONDARY",
			"uptime" : 84676,
			"optime" : Timestamp(1435989328, 1),
			"optimeDate" : ISODate("2015-07-04T05:55:28Z"),
			"self" : true
		},
		{
			"_id" : 4,
			"name" : "192.168.x.xx:27018",
			"health" : 1,
			"state" : 1,
			"stateStr" : "PRIMARY",
			"uptime" : 84674,
			"optime" : Timestamp(1435989328, 1),
			"optimeDate" : ISODate("2015-07-04T05:55:28Z"),
			"lastHeartbeat" : ISODate("2015-06-11T04:02:54Z"),
			"lastHeartbeatRecv" : ISODate("2015-06-11T04:02:55Z"),
			"pingMs" : 2,
			"electionTime" : Timestamp(1435803779, 1),
			"electionDate" : ISODate("2015-07-02T02:22:59Z")
		}
	],
	"ok" : 1
}

参考:http://docs.mongodb.org/v2.6/reference/command/replSetGetStatus


二、诊断性能问题

1、Locks

分析 db.serverStatus() 输出的 globalLock 部分:

"globalLock" : {
		"totalTime" : NumberLong("240481182000"),
		"lockTime" : NumberLong(11670085),
		"currentQueue" : {
			"total" : 0,
			"readers" : 0,
			"writers" : 0
		},
		"activeClients" : {
			"total" : 0,
			"readers" : 0,
			"writers" : 0
		}
	}

If globalLock.currentQueue.total is consistently high, then there is a chance that a large number of requests are waiting for a lock.

This indicates a possible concurrency issue that may be affecting performance.


globalLock.totalTime : The value of totalTime represents the time, in microseconds, since the database last started and creation of the globalLock. 

   This is roughly equivalent to total server uptime.


lockTime/totalTime很大,表示锁花费的时间长,导致性能下降。


2、内存

分析 db.serverStatus() 输出的 mem 部分:

"mem" : {
		"bits" : 64,
		"resident" : 39,
		"virtual" : 2993,
		"supported" : true,
		"mapped" : 1119,
		"mappedWithJournal" : 2238
	}

单位为M.

resident 表示mongodb进程占用的内存,如果是专用服务器,随着mongodb使用内存的增加,这个参数的值会渐渐接近于系统内存。

如果这个参数的值,超过系统内存并且大量的数据存放在磁盘而不在内存中,我们需要增加硬件能力。


mapped 文件映射的内存量,这个值大致与mongodb数据库的大小相同。

If this value is greater than the amount of system memory, some operations will require disk access page faults to read data from virtual memory and negatively affect performance.


3、Page Faults

分析 db.serverStatus() 输出的 extra_info 部分:

"extra_info" : {
		"note" : "fields vary by platform",
		"heap_usage_bytes" : 62941696,
		"page_faults" : 40
	}

通常对大量数据的读取会产生大量的page faults 会使mongodb 性能下降。解决办法是优化sql或扩充内存。


4、连接数

分析 db.serverStatus() 输出的 connections 部分:

"connections" : {
		"current" : 12,
		"available" : 1626,
		"totalCreated" : NumberLong(8014)
	}
	
"globalLock" : {
		"totalTime" : NumberLong("240481182000"),
		"lockTime" : NumberLong(11670085),
		"currentQueue" : {
			"total" : 0,
			"readers" : 0,
			"writers" : 0
		},
		"activeClients" : {
			"total" : 0,
			"readers" : 0,
			"writers" : 0
		}
	}	

说明 :

globalLock.activeClients contains a counter of the total number of clients with active operations in progress or queued.


connections is a container for the following two fields:

  current the total number of current clients that connect to the database instance.

  available the total number of unused collections available for new clients.



上一篇:Mongodb详解与安装

下一篇:mongodb 3.0 配置

相关内容

热门资讯

辟谣!河南公布7起网络谣言典型... 4月,河南持续做好涉企业、“三农”、公共政策、社会热点、文化旅游网络谣言的发现辟除,有力打击谣言传播...
企业买AI,从“尝鲜”变成“算... 【大河财立方 记者 陈薇】以前企业采购人工智能大模型,大多只是抱着试一试的心态:这笔费用归在创新预算...
宇树发布全球首款量产版载人机甲... 【大河财立方消息】 5月12日,据宇树科技官微,宇树发布GD01载人变形机甲,定价390万元起。据介...
中国驻荷兰使馆提醒:在荷中国公... 根据世界卫生组织近日通报,一艘极地探险邮轮上出现了汉坦病毒感染病例。截至5月11日,造成至少8例感染...
新乡市城管局公布典型案例:非法... 近日,新乡市城市管理局对外公布一起危害城市水环境安全的污染环境典型案例。该案经多部门联合溯源、侦办、...
敲诈900多家网店 买家恶意下... 先是申请“仅退款”企图免费得到商品,被商家拒绝后就投诉店铺、恶意下单、索要“和解费”,网店老板曹先生...
公司购买50箱“飞天茅台”,竟... 邢台一公司购买50箱飞天茅台酒,经鉴定竟有41箱为假冒茅台酒,仅9箱为真茅台酒。经查,涉案男子龚某从...
穿越周期 不止“万亿” ——从... 洛阳钼业巴西金矿一角。市民在郑州金融岛参加由好想你公司主办的“好好生活”户外活动。光力科技半导体晶圆...
魏平政出线几率高!国民党整合拼... 海峡导报综合报道 国民党迟未公布彰化县长人选,地方盛传,周三国民党中常可能会有答案,引发关注。对此,...
人均奖金600万,知道内存为什... 唯物的中国芯片产业深度观察AI带动存储狂飙,韩国存储大厂SK海力士也跟着起飞。近日,有投行预测其年终...