在 Debian 上监控 MongoDB,可以从系统层、MongoDB 自带工具、第三方监控三个层面来做。下面按实用程度给你一个清晰方案。
mongosh / mongo 命令行mongosh
进入后常用命令:
db.serverStatus() # 整体状态(连接、内存、锁、操作)
db.stats() # 当前库状态
db.currentOp() # 当前正在执行的操作
db.runCommand({ top: 1 }) # 集合读写统计
日志位置(常见):
/var/log/mongodb/mongod.log
实时查看:
tail -f /var/log/mongodb/mongod.log
top / htop
iostat -x 1
df -h
free -m
systemctl status mongod
journalctl -u mongod -f
wget https://github.com/percona/mongodb_exporter/releases/download/v0.40.0/mongodb_exporter-0.40.0.linux-amd64.tar.gz
tar xzf mongodb_exporter-*.tar.gz
运行:
./mongodb_exporter \
--mongodb.uri=mongodb://localhost:27017
scrape_configs:
- job_name: mongodb
static_configs:
- targets: ['localhost:9216']
connections.currentmem.residentreplication.laglocksdb.setProfilingLevel(1, { slowms: 100 })
db.system.profile.find().sort({ ts: -1 }).limit(10)
✅ 开发:mongosh + 日志
✅ 生产:Prometheus + Grafana + Exporter
✅ 企业:Ops Manager
如果你告诉我:
我可以直接给你一套可复制的监控配置。