Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nil pointer panic when monitoring a mongodb with no username and password set #110

Open
yeya24 opened this issue Nov 8, 2018 · 2 comments

Comments

@yeya24
Copy link

yeya24 commented Nov 8, 2018

Start mongodb in 192.168.2.254 centos 7 with no username and password set

docker run -d -p 27017:27017 mongo:4.1

Then I start the exporter binary in another centos in the same subnet

./mongodb_exporter-linux-amd64 -mongodb.uri mongodb://192.168.2.254:27017

The error is

Listening on :9001 (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=0x508228]

goroutine 35 [running]:
panic(0x73d340, 0xc4200100d0)
	/usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/dcu/mongodb_exporter/collector.(*PreloadStats).Export(0x0, 0xc4201521e0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/collector/metrics.go:363 +0x38
github.com/dcu/mongodb_exporter/collector.(*ReplStats).Export(0xc4202100c0, 0xc4201521e0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/collector/metrics.go:352 +0x90
github.com/dcu/mongodb_exporter/collector.(*MetricsStats).Export(0xc4200f7c80, 0xc4201521e0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/collector/metrics.go:435 +0x4c7
github.com/dcu/mongodb_exporter/collector.(*ServerStatus).Export(0xc42008fae0, 0xc4201521e0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/collector/server_status.go:111 +0x1f9
github.com/dcu/mongodb_exporter/collector.(*MongodbCollector).collectServerStatus(0xc420014eb0, 0xc42016aea0, 0xc4201521e0, 0x7235e0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/collector/mongodb_collector.go:85 +0xe3
github.com/dcu/mongodb_exporter/collector.(*MongodbCollector).Collect(0xc420014eb0, 0xc4201521e0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/collector/mongodb_collector.go:64 +0x2d4
github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).Gather.func2(0xc42014a090, 0xc4201521e0, 0x928900, 0xc420014eb0)
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:433 +0x63
created by github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus.(*Registry).Gather
	/Users/dc/code/go/src/github.com/dcu/mongodb_exporter/vendor/github.com/prometheus/client_golang/prometheus/registry.go:434 +0x326
@ealexhaywood
Copy link

Check out https://github.com/percona/mongodb_exporter which is a fork of this repository and seems more active than this one. I'm curious if it would resolve this issue

@yeya24 yeya24 closed this as completed Nov 17, 2018
@yeya24 yeya24 reopened this Nov 17, 2018
@n1o
Copy link

n1o commented Apr 15, 2019

Hi @yeya24 ,
does this issue occur if you provide username and password?
Because I am experiencing the same issue, but i have not tried it with credentials. This issue appeared after I upgrade from mongo 3.6 to 4.1.9. However I was able to apply the following quick fix:

func (replStats *ReplStats) Export(ch chan<- prometheus.Metric) {
	replStats.Apply.Export(ch)
	replStats.Buffer.Export(ch)
	replStats.Network.Export(ch)

	if replStats.PreloadStats != nil {
		replStats.PreloadStats.Export(ch)
	}
	// 3.0+ only
	if replStats.Executor != nil {
		replStats.Executor.Export(ch)
	}
}

In metrics.go
This way you probably loose some metrics, but the rest should work.

sprohaska added a commit to nogproject/mongodb_exporter that referenced this issue Apr 23, 2019
See discussion in issue dcu#110
<dcu#110>.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
sprohaska added a commit to nogproject/mongodb_exporter that referenced this issue Apr 23, 2019
bgriffinte pushed a commit to bgriffinte/mongodb_exporter_dcu that referenced this issue Feb 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants