在Debian上监控MongoDB性能可使用以下工具和方法:
mongostat
mongostat --host localhost:27017
。mongotop
mongotop --host localhost:27017
。db.serverStatus()
mongo localhost:27017/admin --eval "db.serverStatus()"
。Prometheus + Grafana
mongodb-exporter
采集指标,配置prometheus.yml
添加目标(如- targets: ['localhost:9216']
)。# Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-2.30.3.linux-amd64.tar.gz
# Grafana
wget https://dl.grafana.com/oss/release/grafana-8.2.0.linux-amd64.tar.gz
tar -zxvf grafana-8.2.0.linux-amd64.tar.gz
云监控服务
/etc/mongod.conf
中启用,记录执行时间超过指定阈值的查询。operationProfiling:
mode: slowOp
slowOpThresholdMs: 100
logrotate
配置定期压缩日志,避免文件过大。根据需求选择工具,原生工具适合快速排查,第三方方案适合大规模集群的长期监控。