mzupan / nagios-plugin-mongodb

A Nagios plugin to check the status of MongoDB
BSD 2-Clause "Simplified" License
346 stars 274 forks source link

Can't get DB/collection/index stats in a replica set. #206

Open fuqqer opened 7 years ago

fuqqer commented 7 years ago

Trying to run check_mongodb.py against a replica set with this - check_mongodb.py -H mongohostX -A database_indexes -P 27017 -d database -u mongouser -p secret

it returns - CRITICAL - General MongoDB Error: 'module' object has no attribute 'Secondary'

I have tried connecting to both my primary and secondary servers in a replica set and get the same failure.

bert2002 commented 7 years ago

Same problem here and only for for the replication_lag check. Any solution? Using python 2.7.6 on Ubuntu 14.04 and pymongo 2.6.3.

bert2002 commented 7 years ago

Any thoughts or ideas?

wpowell-ossg commented 7 years ago

Yep, it will be the read preference that it is trying to set. Either your pymongo driver or mongodb instance is low rev and has a problem setting read preference to secondary. Initially try commenting out the line "set_read_preference(con.admin)" on line 961 of the check mongodb script to see if it runs ok, then let us know version of pymongo driver and mongodb

wpowell-ossg commented 7 years ago

...also is this a standalone db or a replica set, and if it IS an RS, how many nodes?

bert2002 commented 7 years ago

Hi, i commented "set_read_preference(con.admin)" in line 119 (961 does not have the mentioned value). python-pymongo is 2.6.3-1build1 and mongodb 3.2.4. The setup is a master with one replicate set and I run the scrip against the replicate.

/usr/lib/nagios/plugins/check_mongodb.py -H $ADDRESS -A replication_lag

bert2002 commented 7 years ago

Argh. Just used the latest version of the plugin and it seems to work:

python check_mongodb.py -H $ADDRESS -A replication_lag OK - State: 7 (Arbiter on port 27017)

wpowell-ossg commented 7 years ago

Be aware that you cannot do stat quries on Arbiters. This code in the mongo_connect function just returns that message:

    if 'arbiterOnly' in result and result['arbiterOnly'] == True:
        print "OK - State: 7 (Arbiter on port %s)" % (port)
        sys.exit(0)

So to get a valid result for the repl lag, you will need to query a secondary or primary, not an arbiter

bert2002 commented 7 years ago

Ohhh thats a good point. When I query a primary I get this:

/usr/lib/nagios/plugins/check_mongodb.py -H $ADDRESS -A replication_lag OK - This is the primary.

Looks much better now :) Thx for pointing this out.