原因
1 及时获得应用的运行状态信息
2 第一时间发现问题并解决
内容
CPU
内存
磁盘I/O
应用程序(MongoDB)
进程监控(ps -aux)
错误日志
集群监控
服务状态
# 内存相关
demo:PRIMARY> db.serverStatus().mem
{ "bits" : 64, "resident" : 104, "virtual" : 1961, "supported" : true }
# 连接到本机处于活动状态的连接数
demo:PRIMARY> db.serverStatus().connections
{
"current" : 9,
"available" : 52419,
"totalCreated" : 17,
"active" : 3,
"exhaustIsMaster" : 1,
"awaitingTopologyChanges" : 1
}
# 锁参数
demo:PRIMARY> db.serverStatus().locks
{
"ParallelBatchWriterMode" : {
"acquireCount" : {
"r" : NumberLong(89524)
}
},
"ReplicationStateTransition" : {
"acquireCount" : {
"w" : NumberLong(111017),
"W" : NumberLong(2)
},
"acquireWaitCount" : {
"w" : NumberLong(2),
"W" : NumberLong(2)
},
"timeAcquiringMicros" : {
"w" : NumberLong(8883),
"W" : NumberLong(38)
}
},
"Global" : {
"acquireCount" : {
"r" : NumberLong(50183),
"w" : NumberLong(60829),
"W" : NumberLong(5)
}
},
"Database" : {
"acquireCount" : {
"r" : NumberLong(43121),
"w" : NumberLong(59971),
"W" : NumberLong(15)
}
},
"Collection" : {
"acquireCount" : {
"r" : NumberLong(1331),
"w" : NumberLong(59423),
"W" : NumberLong(6)
}
},
"Mutex" : {
"acquireCount" : {
"r" : NumberLong(100161)
}
},
"oplog" : {
"acquireCount" : {
"r" : NumberLong(42869),
"w" : NumberLong(2)
}
}
}
# 复制相关
demo:PRIMARY> db.serverStatus().opcountersRepl
{
"insert" : NumberLong(0),
"query" : NumberLong(0),
"update" : NumberLong(0),
"delete" : NumberLong(0),
"getmore" : NumberLong(0),
"command" : NumberLong(0)
}
数据库状态
demo:PRIMARY> db.stats()
{
"db" : "test", # 数据库名称
"collections" : 28, # 数据库当前保持连接数数
"views" : 0,
"objects" : 114786031, # 数据库当前总数据行数
"avgObjSize" : 1444.1829317367024, # 平均每行数据大小
"dataSize" : 165772026772, # 所有数据总大小
"storageSize" : 44605587456, # 所有数据占用磁盘大小
"numExtents" : 0,
"indexes" : 103, # system.indexes表数据行数
"indexSize" : 3495432192, # 索引占用磁盘大小
"fsUsedSize" : 204369350656,
"fsTotalSize" : 211243667456,
"ok" : 1
}
mongostat
# 使用方式
mongostat --host ip:port -u "用户名" -p "密码" --authenticationDatabase "admin"
insert query update delete getmore command dirty used flushes vsize res qrw arw net_in net_out conn time
*0 *0 *0 *0 0 2|0 0.0% 0.0% 0 1.51G 87.0M 0|0 1|0 158b 84.1k 1 May 5 20:35:47.238
*0 *0 *0 *0 0 2|0 0.0% 0.0% 0 1.51G 87.0M 0|0 1|0 158b 84.2k 1 May 5 20:35:48.237
参数说明
参数 | 说明 |
---|---|
insert | 每秒插入量 |
query | 每秒查询量 |
update | 每秒更新量 |
delete | 每秒删除量 |
conn | 当前连接数 |
qr&qw | 客户端排队长度 |
ar&aw | 活跃客户端数量 |
time | 当前时间 |
mongotop
mongotop --host ip:port -u "用户名" -p "密码" --authenticationDatabase "admin" 60 # 默认1秒输出一次,加上参数为每60秒一次
ns total read write 2021-05-05T20:48:37+08:00
admin.system.roles 0ms 0ms 0ms
admin.system.version 0ms 0ms 0ms
config.system.sessions 0ms 0ms 0ms
config.transactions 0ms 0ms 0ms
local.oplog.rs 0ms 0ms 0ms
local.system.replset 0ms 0ms 0ms
参数说明
参数 | 说明 |
---|---|
ns | namespace,由库名+点号+集合名组成 |
total | 指定周期内每次统计mongod实例的读写总耗时时长 |
read | 指定周期内每次统计的读操作耗时时长 |
write | 指定周期内每次统计的写操作耗时时长 |
网友评论