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

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...