lib/sensu-plugins-mongodb/metics.rb in sensu-plugins-mongodb-1.3.0 vs lib/sensu-plugins-mongodb/metics.rb in sensu-plugins-mongodb-1.4.0
- old
+ new
@@ -86,16 +86,31 @@
puts 'Error checking serverStatus: ' + e.message
puts e.backtrace.inspect
end
end
+ # Fetches the replicaset status of the server (which includes the metrics).
+ #
+ # @return [Mash, nil] the document showing the replicaset status or nil.
+ def replicaset_status
+ status = get_mongo_doc('replSetGetStatus' => 1)
+ return nil if status.nil?
+ return status
+ rescue StandardError => e
+ if @debug
+ puts 'Error checking replSetGetStatus: ' + e.message
+ puts e.backtrace.inspect
+ end
+ end
+
# Fetches metrics for the server we are connected to.
#
# @return [Mash] the metrics for the server.
# rubocop:disable Metrics/AbcSize
def server_metrics
server_status = self.server_status
+ replicaset_status = self.replicaset_status
server_metrics = {}
# Handle versions like "2.6.11-pre" etc
mongo_version = server_status['version'].gsub(/[^0-9\.]/i, '')
server_metrics['lock.ratio'] = sprintf('%.5f', server_status['globalLock']['ratio']).to_s unless server_status['globalLock']['ratio'].nil?
@@ -305,9 +320,15 @@
server_metrics['metrics.repl.network.readersCreated'] = repl['network']['readersCreated']
server_metrics['metrics.repl.preload.docs_num'] = repl['preload']['docs']['num']
server_metrics['metrics.repl.preload.docs_totalMillis'] = repl['preload']['docs']['totalMillis']
server_metrics['metrics.repl.preload.indexes_num'] = repl['preload']['indexes']['num']
server_metrics['metrics.repl.preload.indexes_totalMillis'] = repl['preload']['indexes']['totalMillis']
+
+ # Metrics (replicaset status)
+ # MongoDB will fail if not running with --replSet, hence the check for nil
+ unless replicaset_status.nil?
+ server_metrics['metrics.replicaset.state'] = replicaset_status['myState']
+ end
# Metrics (storage)
if Gem::Version.new(mongo_version) >= Gem::Version.new('2.6.0')
freelist = server_status['metrics']['storage']['freelist']
server_metrics['metrics.storage.freelist.search_bucketExhauseted'] = freelist['search']['bucketExhausted']