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 配置

相关内容

热门资讯

徐巧芯剖析赖清德:最怕自己丢掉... 海峡导报综合报道 大罢免投票一周年纪念活动26日举行,台北市长蒋万安出席并怒轰,民进党一年过后仍没有...
中国红十字会总会紧急向广东调拨... 记者从中国红十字会总会了解到,针对台风“红霞”给广东造成的灾情,中国红十字会总会启动四级应急响应,紧...
这些少年,正被“毒蛋”围猎 李梦抽了几口电子烟,吐出了白色的烟雾,有一股浓烈的水果香味。随后,她看着自己握电子烟的手,跟身边人说...
蒋万安号召“倒阁”,卢秀燕认为... 海峡导报综合报道 台北市长蒋万安27日抛出震撼议题,表示多名民代向他提议推动“倒阁”,要求台行政机构...
特朗普将在白宫会见两位重要客人 俄乌战争仍未结束,美伊冲突又有升级风险。在此背景下,美国总统特朗普将在白宫接见乌克兰和以色列领导人。...
新租客打扫卧室柜子上掉落4万元... 近日,莲前西路某小区内,张倩签下一套房子的租赁合同。当天上午,她带着12岁的大女儿周馨怡和11岁的小...
六部门通告:禁止涉军队退役报废... 关于禁止涉军队退役报废装备销售活动的通告近年来,部分经营者在线上线下公开销售涉及我军退役报废装备(指...
九寨沟景区发生泥石流,部分道路... 7月26日,九寨沟风景名胜区管理局发布泥石流灾害通报:2026年7月26日15时50分,九寨沟景区局...
空调26度不凉是什么原因 从空调内部元器件来说,不凉的原因有可能是温度传感器出现故障了,也有可能是空调压缩机或者铜管出现问题,...
鲸鸿动能携手香港国际机场、鸿蒙...   2026 年 7 月 25 日,十余位鸿蒙车主组成的车队从珠海出发,经港珠澳大桥通关抵达香港国际...