MongoDB 第12章 性能监控
1、MongoStat
此工具可以快速的查看某组运行中的MongoDB实例的统计信息,用法如下:
[root@localhost bin]# ./mongostat
connected to: 127.0.0.1
insert query update delete getmore command flushes mapped vsize res faults locked db idx miss % qr|qw ar|aw netIn netOut conn time
*0 *0 *0 *0 0 1|0 0 320m 939m 37m 1 zhangsan:0.1% 0 0|0 0|0 62b 3k 2 21:49:23
*0 *0 *0 *0 0 1|0 0 320m 939m 37m 0 zhangsan:0.0% 0 0|0 0|0 62b 3k 2 21:49:24
*0 *0 *0 *0 0 1|0 0 320m 939m 37m 0 zhangsan:0.0% 0 0|0 0|0 62b 3k 2 21:49:25
*0 *0 *0 *0 0 1|0 0 320m 939m 37m 0 zhangsan:0.0% 0 0|0 0|0 62b 3k 2 21:49:26
字段说明:
insert每秒插入量
query每秒查询量
update每秒更新量
delete每秒删除量
locked锁定量
qr|qw客户端查询排队长度(读|写)
ar|aw活跃客户端量(读|写)
conn连接数
time当前时间
它每秒中刷新一次状态值,提供良好的可读性,通过这些参数可以观察到一个整体的性能情况。
2、db.serverStatus
这个命令是最常用也是最基础的查看实例运行状态的命令之一,下面我们看一下它的输出:
> db.serverStatus()
{
"host" : "localhost.localdomain",
"version" : "2.6.6", --服务器版本
"process" : "mongod",
"pid" : NumberLong(29293),
"uptime" : 23180,--启动时间(秒)
"uptimeMillis" : NumberLong(23179942),
"uptimeEstimate" : 21041,
"localTime" : ISODate("2015-01-04T13:53:03.792Z"),
"asserts" : {
"regular" : 0,
"warning" : 0,
"msg" : 0,
"user" : 0,
"rollovers" : 0
},
"backgroundFlushing" : {
"flushes" : 386,
"total_ms" : 99,
"average_ms" : 0.25647668393782386,
"last_ms" : 0,
"last_finished" : ISODate("2015-01-04T13:52:44.259Z")
},
"connections" : {
"current" : 2,--当前活动连接量
"available" : 817,--剩余空闲连接量
"totalCreated" : NumberLong(19)
},
"cursors" : {
"note" : "deprecated, use server status metrics",
"clientCursors_size" : 0,
"totalOpen" : 0,
"pinned" : 0,
"totalNoTimeout" : 0,
"timedOut" : 0
},
"dur" : {
"commits" : 29,
"journaledMB" : 0,
"writeToDataFilesMB" : 0,
"compression" : 0,
"commitsInWriteLock" : 0,
"earlyCommits" : 0,
"timeMs" : {
"dt" : 3038,
"prepLogBuffer" : 0,
"writeToJournal" : 0,
"writeToDataFiles" : 0,
"remapPrivateView" : 0
}
},
"extra_info" : {
"note" : "fields vary by platform",
"heap_usage_bytes" : 62803792,
"page_faults" : 36
},
"globalLock" : {
"totalTime" : NumberLong("23179943000"),
"lockTime" : NumberLong(3334379),
"currentQueue" : {
"total" : 0,--当前全部队列量
"readers" : 0,--读请求队列量
"writers" : 0--写请求队列量
},
"activeClients" : {
"total" : 0,--当前全部客户端连接量
"readers" : 0,--客户端读请求量
"writers" : 0--客户端写请求量
}
},
"indexCounters" : {
"accesses" : 38,--索引被访问量
"hits" : 38,--索引命中量
"misses" : 0,--索引偏差两
"resets" : 0,
"missRatio" : 0--索引偏差率(未命中率)
},
"locks" : {
"." : {
"timeLockedMicros" : {
"R" : NumberLong(954466),
"W" : NumberLong(3334379)
},
"timeAcquiringMicros" : {
"R" : NumberLong(5652043),
"W" : NumberLong(133798)
}
},
"admin" : {
"timeLockedMicros" : {
"r" : NumberLong(255071),
"w" : NumberLong(0)
},
"timeAcquiringMicros" : {
"r" : NumberLong(67318),
"w" : NumberLong(0)
}
},
"local" : {
"timeLockedMicros" : {
"r" : NumberLong(82150),
"w" : NumberLong(17)
},
"timeAcquiringMicros" : {
"r" : NumberLong(18964),
"w" : NumberLong(1)
}
},
"zhangsan" : {
"timeLockedMicros" : {
"r" : NumberLong(8788),
"w" : NumberLong(1673999)
},
"timeAcquiringMicros" : {
"r" : NumberLong(1409),
"w" : NumberLong(55)
}
},
"temp" : {
"timeLockedMicros" : {
"r" : NumberLong(340424),
"w" : NumberLong(2765621)
},
"timeAcquiringMicros" : {
"r" : NumberLong(111659),
"w" : NumberLong(6212)
}
},
"test" : {
"timeLockedMicros" : {
"r" : NumberLong(602182),
"w" : NumberLong(437948)
},
"timeAcquiringMicros" : {
"r" : NumberLong(73084),
"w" : NumberLong(85)
}
}
},
"network" : {
"bytesIn" : 66494,--发给此服务器的数据量(单位:byte)
"bytesOut" : 865147,--此服务器发出的数据量(单位:byte)
"numRequests" : 851--发给此服务器的请求量
},
"opcounters" : {
"insert" : 9,--插入操作的量
"query" : 1928,--查询操作的量
"update" : 8,--更新操作的量
"delete" : 2,
"getmore" : 0,
"command" : 812--其他操作的量
},
"opcountersRepl" : {
"insert" : 0,
"query" : 0,
"update" : 0,
"delete" : 0,
"getmore" : 0,
"command" : 0
},
"recordStats" : {
"accessesNotInMemory" : 0,
"pageFaultExceptionsThrown" : 0,
"admin" : {
"accessesNotInMemory" : 0,
"pageFaultExceptionsThrown" : 0
},
"local" : {
"accessesNotInMemory" : 0,
"pageFaultExceptionsThrown" : 0
},
"temp" : {
"accessesNotInMemory" : 0,
"pageFaultExceptionsThrown" : 0
},
"test" : {
"accessesNotInMemory" : 0,
"pageFaultExceptionsThrown" : 0
},
"zhangsan" : {
"accessesNotInMemory" : 0,
"pageFaultExceptionsThrown" : 0
}
},
"writeBacksQueued" : false,
"mem" : {
"bits" : 64,--64位系统
"resident" : 37,--占用物理内存量
"virtual" : 939,--虚拟内存量
"supported" : true,--是否支持扩展内存
"mapped" : 320,
"mappedWithJournal" : 640
},
"metrics" : {
"cursor" : {
"timedOut" : NumberLong(0),
"open" : {
"noTimeout" : NumberLong(0),
"pinned" : NumberLong(0),
"total" : NumberLong(0)
}
},
"document" : {
"deleted" : NumberLong(1),
"inserted" : NumberLong(9),
"returned" : NumberLong(428),
"updated" : NumberLong(8)
},
"getLastError" : {
"wtime" : {
"num" : 0,
"totalMillis" : 0
},
"wtimeouts" : NumberLong(0)
},
"operation" : {
"fastmod" : NumberLong(1),
"idhack" : NumberLong(0),
"scanAndOrder" : NumberLong(0)
},
"queryExecutor" : {
"scanned" : NumberLong(2),
"scannedObjects" : NumberLong(2)
},
"record" : {
"moves" : NumberLong(0)
},
"repl" : {
"apply" : {
"batches" : {
"num" : 0,
"totalMillis" : 0
},
"ops" : NumberLong(0)
},
"buffer" : {
"count" : NumberLong(0),
"maxSizeBytes" : 268435456,
"sizeBytes" : NumberLong(0)
},
"network" : {
"bytes" : NumberLong(0),
"getmores" : {
"num" : 0,
"totalMillis" : 0
},
"ops" : NumberLong(0),
"readersCreated" : NumberLong(0)
},
"preload" : {
"docs" : {
"num" : 0,
"totalMillis" : 0
},
"indexes" : {
"num" : 0,
"totalMillis" : 0
}
}
},
"storage" : {
"freelist" : {
"search" : {
"bucketExhausted" : NumberLong(0),
"requests" : NumberLong(399),
"scanned" : NumberLong(731)
}
}
},
"ttl" : {
"deletedDocuments" : NumberLong(0),
"passes" : NumberLong(386)
}
},
"ok" : 1
}
>
3、db.stats
db.stats查看数据库状态信息,使用样例如下:
> db.stats()
{
"db" : "test",
"collections" : 16,--collection数量
"objects" : 152,--对象数量
"avgObjSize" : 72.42105263157895,--对象平均大小
"dataSize" : 11008,--数据大小
"storageSize" : 131072,--数据大小(含预分配空间)
"numExtents" : 16,--事件数量
"indexes" : 20,--索引数量
"indexSize" : 163520,--索引文件大小
"fileSize" : 67108864,--文件大小
"nsSizeMB" : 16,
"dataFileVersion" : {
"major" : 4,
"minor" : 5
},
"extentFreeList" : {
"num" : 1,
"totalSize" : 131072
},
"ok" : 1--本次取stats是否正常
}
>
通过这个工具,可以查看当前数据库的基本信息。
4、第三方工具
MongoDB从一面世就得到了众多开源爱好者和团队的重视,在常用的监控框架如cacti、Nagios、Zabbix等基础上进行扩展,进行MongoDB的监控都是非常方便的。
- 点赞
- 收藏
- 关注作者
评论(0)