Skip to content

Commit 83d132e

Browse files
committed
adding --connect option and use it
- when retrieving metrics it will now pull only local metrics rather than all nodes in the reiplca set. To revert this behavior you can add `--connect replica_set` - control of connection type for metric gatherering scripts Signed-off-by: Ben Abrams <[email protected]>
1 parent 1534adb commit 83d132e

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This CHANGELOG follows the format located [here](https://github.com/sensu-plugins/community/blob/master/HOW_WE_CHANGELOG.md)
55

66
## [Unreleased]
7-
### Fixed
8-
- Ensure Server status/Replicaset stats are current host's, not host from read preference (@naemon)
7+
### Breaking Changes
8+
- `--connect` now defaults to `:direct` so that Server status/Replicaset stats are current host'srather than all metrics in the replica set (@naemon)
9+
10+
### Added
11+
- exposed `--connect` which controls how it connects. Valid values are `:direct`, `:replica_set` (mongo client default), and `:sharded`. (@naemon) (@majormoses)
912

1013
## [2.0.2] - 2018-03-17
1114
### Fixed

bin/metrics-mongodb-replication.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ class MongoDB < Sensu::Plugin::Metric::CLI::Graphite
103103
long: '--debug',
104104
default: false
105105

106+
option :connect,
107+
description: 'The connection method to use',
108+
long: `--connect`,
109+
in: %i[direct replica_set sharded],
110+
proc: proc(&:to_sym),
111+
default: :direct
112+
106113
def get_mongo_doc(command)
107114
rs = @db.command(command)
108115
unless rs.successful?

bin/metrics-mongodb.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ class MongoDB < Sensu::Plugin::Metric::CLI::Graphite
9999
long: '--require-master',
100100
default: false
101101

102+
option :connect,
103+
description: 'The connection method to use',
104+
long: `--connect`,
105+
in: %i[direct replica_set sharded],
106+
proc: proc(&:to_sym),
107+
default: :direct
108+
102109
def run
103110
Mongo::Logger.logger.level = Logger::FATAL
104111
@debug = config[:debug]

lib/sensu-plugins-mongodb/metrics.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,15 @@ def get_mongo_client(db_name)
369369
ssl_key = @config[:ssl_key]
370370
ssl_ca_cert = @config[:ssl_ca_cert]
371371
ssl_verify = @config[:ssl_verify]
372+
connect = @config[:connect]
372373

373374
if Gem.loaded_specs['mongo'].version < Gem::Version.new('2.0.0')
374375
MongoClient.new(host, port)
375376
else
376377
address_str = "#{host}:#{port}"
377378
client_opts = {}
378379
client_opts[:database] = db_name
379-
client_opts[:connect] = :direct
380+
client_opts[:connect] = connect
380381
unless db_user.nil?
381382
client_opts[:user] = db_user
382383
client_opts[:password] = db_password

0 commit comments

Comments
 (0)