sensu-plugins / sensu-plugins-mongodb

This plugin provides native MongoDB instrumentation for monitoring and metrics collection, including: service health, database connectivity, replication lag/status, `oplog` monitoring, collection-specific metrics, and more.

Home Page:http://sensu-plugins.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Replicaset/Server stats are not own data, but read-preference's data

naemono opened this issue · comments

Using the mongo client without :connect :direct option is returning the replSetGetStatus, and serverStatus information for whatever the read preference is set to, such as the master, and not your own information.

Example

local rs.status

> rs.status()
{
	"set" : "1b686e5c-7630-46e6-9d9e-80108b2f92e1",
	"date" : ISODate("2017-10-02T16:35:16.305Z"),
	"myState" : 2,
	"term" : NumberLong(2),
	"syncingTo" : "redacted",

output

# /opt/sensu/embedded/bin/ruby /etc/sensu/plugins/metrics-mongodb.rb --user redacted --password redacted | grep replicaset.state
80d05bce-8a92-47e7-8e1a-8d21d7032627.mongodb.metrics.replicaset.state 1 1506961990

https://gist.github.com/naemono/d9a7ef94b030d5e06b4b9dc378ba89aa

Is there any reason this might not be desired and should be behind an option to control it?

@majormoses comment in PR. If an option is preferred, let me know and I'll get that in place. thanks

Yes an option makes sense to me, no real cost and allow people to do things as they see fit.

I would love to see this merged. Is there anything I can help with?

@jindraj it looks like there are two things:

  • The code is out of date and needs to be rebased, I can take a look at that
  • We need a test be it automated or manual

I resolved the conflict, if someone can provide a working test I am happy to accept it. The test if manual should be something along these lines:

  1. command run (with all options, redact if needed)
  2. the output of a successful run

I tried to provide the test, but I'm hitting the wall.

  1. backticks around --connect long option causes error below. This needs to be in single quotes.
    bin/metrics-mongodb.rb:104:in ``': No such file or directory - --connect (Errno::ENOENT)

  2. The default seems to work fine (I can confirm I'm connected to a secondary and I'm getting for different servers in replicaset different metrics). But when I define it on command line --connect direct I'm getting this error.
    Check failed to run: undefined method `to_sym' for true:TrueClass Did you mean? to_s, ["/var/lib/gems/2.3.0/gems/mixlib-cli-1.7.0/lib/mixlib/cli.rb:290:in `block (3 levels) in opt_parser'", "/usr/lib/ruby/2.3.0/optparse.rb:1540:in `block in parse_in_order'", "/usr/lib/ruby/2.3.0/optparse.rb:1527:in `catch'", "/usr/lib/ruby/2.3.0/optparse.rb:1527:in `parse_in_order'", "/usr/lib/ruby/2.3.0/optparse.rb:1521:in `order!'", "/usr/lib/ruby/2.3.0/optparse.rb:1613:in `permute!'", "/usr/lib/ruby/2.3.0/optparse.rb:1635:in `parse!'", "/var/lib/gems/2.3.0/gems/mixlib-cli-1.7.0/lib/mixlib/cli.rb:230:in `parse_options'", "/var/lib/gems/2.3.0/gems/sensu-plugin-2.0.1/lib/sensu-plugin/cli.rb:13:in `initialize'", "/var/lib/gems/2.3.0/gems/sensu-plugin-2.0.1/lib/sensu-plugin/cli.rb:57:in `new'", "/var/lib/gems/2.3.0/gems/sensu-plugin-2.0.1/lib/sensu-plugin/cli.rb:57:in `block in <class:CLI>'"]

sadly I don't know how to resolve this.

@jindraj thats why I ask for tests on changes I do not know how to test myself. I will try to find some time this weekend to take a closer look at the code to see if I can see why its failing. If I can figure it out I will push to that pull request and will ask for another test.

@jindraj I took a look at the code and believe I have resolved the issue, can you please pull the branch again for another test and report back?

I had completely forgotten about this, and just happened to notice conversations concerning this via email. I'm nearly complete working through an integration test that will only run when specified

--tag integration

that shows this functionality using a full mongodb replicaset brought up in docker. I assume you wouldn't want to run this full test with the other test suites normally? Or would you prefer this in another manner? Any preferences?