MongoDB_exporter无法导出未授权集群全部指标,如何监控集群?
问题描述
使用mongodb_exporter-2.37.0.linux-amd64.tar.gz连接未授权MongoDB集群(未创建用户),执行命令:
sudo curl http://localhost:9100/metrics
仅返回少量基础指标(包含Go运行时、进程状态及mongodb_up等),无法获取完整的数据库操作类指标。
当前使用的systemd服务配置文件如下:
# /lib/systemd/system/mongodb_exporter.service [Unit] Description=MongoDB Exporter User=prometheus [Service] Type=simple Restart=always Environment="MONGODB_URI=mongodb://127.0.0.1:48800" ExecStart=/usr/local/bin/mongodb_exporter --web.listen-address=:9100 [Install] WantedBy=multi-user.target
期望获取完整的MongoDB指标,需如何配置监控?
解决方法
修改exporter启动参数,启用全量指标收集
mongodb_exporter默认仅启用基础指标收集器,需显式添加参数开启全量收集,或按需指定具体收集器。修改服务配置文件中的ExecStart行:ExecStart=/usr/local/bin/mongodb_exporter --web.listen-address=:9100 --collect-all若无需全量指标,可指定具体收集器(如
--collect-dbstats收集数据库统计、--collect-collection-stats收集集合统计等),多个收集器用空格分隔。优化MongoDB连接URI(可选但推荐)
对于未授权集群,在URI中指定authSource=admin可提升连接兼容性,避免部分收集器因认证源问题无法工作:Environment="MONGODB_URI=mongodb://127.0.0.1:48800/?authSource=admin"重启服务使配置生效
执行以下命令重新加载systemd配置并重启exporter:sudo systemctl daemon-reload sudo systemctl restart mongodb_exporter验证指标完整性
再次执行curl命令检查指标:sudo curl http://localhost:9100/metrics此时应能看到数据库操作、集合统计等全量MongoDB指标。
内容的提问来源于stack exchange,提问作者Duranta Patra
相关产品推荐
相关产品推荐

