【Prometheus系列】mongodb_exporter 监控 MongoDB报错
最近在研究 Prometheus ,发现遇到的很多问题,不知是不是我的搜索方式不对,根本找不到合适的解决方案,所以,自己动手丰衣足食。
以后会继续更新遇到的问题以及解决方案,希望对大家有帮助,如果有其他问题热烈欢迎私信或者评论区见。
问题一:监控云数据库 MongoDB 4.2 版本报错
问题描述
MongoDB版本升级后,mongodb_exporter 任务启动失败。
报错信息
Listening on 171.24.26.100:9625 (scheme=HTTP, secured=no, clientValidation=no)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x77cb0d]
goroutine 38 [running]:
github.com/dcu/mongodb_exporter/collector.(*PreloadStats).Export(0x0, 0xc0000a8c00)
/root/go/src/github.com/dcu/mongodb_exporter/collector/metrics.go:363 +0x2d
github.com/dcu/mongodb_exporter/collector.(*ReplStats).Export(0xc00000e8e0, 0xc0000a8c00)
/root/go/src/github.com/dcu/mongodb_exporter/collector/metrics.go:352 +0x90
github.com/dcu/mongodb_exporter/collector.(*MetricsStats).Export(0xc0000af9f0, 0xc0000a8c00)
/root/go/src/github.com/dcu/mongodb_exporter/collector/metrics.go:448 +0x4ec
github.com/dcu/mongodb_exporter/collector.(*ServerStatus).Export(0xc0000bcc60, 0xc0000a8c00)
/root/go/src/github.com/dcu/mongodb_exporter/collector/server_status.go:118 +0x2f2
github.com/dcu/mongodb_exporter/collector.(*MongodbCollector).collectServerStatus(0xc0000f2280, 0xc000093ba0, 0xc0000a8c00, 0xc000203e60)
/root/go/src/github.com/dcu/mongodb_exporter/collector/mongodb_collector.go:144 +0xc3
github.com/dcu/mongodb_exporter/collector.(*MongodbCollector).Collect(0xc0000f2280, 0xc0000a8c00)
/root/go/src/github.com/dcu/mongodb_exporter/collector/mongodb_collector.go:93 +0x2e8
github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func2(0xc0000a2b70, 0xc0000a8c00, 0x921ae0, 0xc0000f2280)
/root/go/src/github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:433 +0x6b
created by github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).Gather
/root/go/src/github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:431 +0x2e9
Listening on 172.24.36.45:9625 (scheme=HTTP, secured=no, clientValidation=no)
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x77cb0d]
问题解决
官网指定的 mongodb_exporter ( 下载地址),针对MongoDB4.0以上版本不兼容,需要重新安装新的 mongodb_exporter (下载地址),重新安装后,问题解决。
问题二:监控云数据库 MongoDB 3.2 版本报错
问题描述
在解决问题一的后,发现 mongodb_exporter 又有新的报错信息。
报错信息
time="2022-03-02T18:11:47+08:00" level=error msg="Failed to get replSetGetConfig: replSetGetConfig is forbidden by cloud provider for security reason, you can run `db.runCommand({listCommands: 1})` to get the supported command list, bad cmd: '{ replSetGetConfig: 1 }'." source="replset_conf.go:115"
time="2022-03-02T18:11:51+08:00" level=error msg="Failed to get replSetGetConfig: replSetGetConfig is forbidden by cloud provider for security reason, you can run `db.runCommand({listCommands: 1})` to get the supported command list, bad cmd: '{ replSetGetConfig: 1 }'." source="replset_conf.go:115"
time="2022-03-02T18:11:52+08:00" level=error msg="Failed to get replSetGetConfig: replSetGetConfig is forbidden by cloud provider for security reason, you can run `db.runCommand({listCommands: 1})` to get the supported command list, bad cmd: '{ replSetGetConfig: 1 }'." source="replset_conf.go:115"
问题解决
通过定位报错信息 db.runCommand({listCommands: 1}) ,原来云数据库版本不同会限制一些命令,详见(命令限制),listCommands 从mongodb_20190725_1.1.8版本开始支持,mongodb_20190409_1.1.7及之前版本不支持该命令,故升级小版本后,问题解决。