Skip to content

Commit

Permalink
7391 FIX mk_mongodb: don't crash upon missing flushing info
Browse files Browse the repository at this point in the history
The plugin no longer crashes the server does not report info
on 'backgroundFlushing', as is the case for MongoDB 4.0 onwards.

CMK-1885

Change-Id: Ieda32ee6d42645e1ce06fee1c20d30141abbad4f
  • Loading branch information
Moritz Kiemer committed Apr 4, 2019
1 parent d499ac1 commit 22e0ca3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .werks/7391
@@ -0,0 +1,11 @@
Title: mk_mongodb: don't crash upon missing flushing info
Level: 1
Component: checks
Compatible: compat
Edition: cre
Version: 1.6.0i1
Date: 1554298869
Class: fix

The plugin no longer crashes the server does not report info
on 'backgroundFlushing', as is the case for MongoDB 4.0 onwards.
16 changes: 12 additions & 4 deletions agents/plugins/mk_mongodb
Expand Up @@ -18,6 +18,17 @@ import time
import pymongo # pylint: disable=import-error


def section_flushing(server_status):
# key is depricated for MongoDB 4.0
flushing_info = server_status.get("backgroundFlushing")
if flushing_info is None:
return
sys.stdout.write("<<<mongodb_flushing>>>\n")
sys.stdout.write("average_ms %s\n" % flushing_info["average_ms"])
sys.stdout.write("last_ms %s\n" % flushing_info["last_ms"])
sys.stdout.write("flushed %s\n" % flushing_info["flushes"])


def main(): # pylint: disable=too-many-branches,too-many-locals
# might be implemented in the future..
host = None
Expand Down Expand Up @@ -110,10 +121,7 @@ def main(): # pylint: disable=too-many-branches,too-many-locals
for key, value in global_lock_info[what].items():
sys.stdout.write("%s %s %s\n" % (what, key, value))

sys.stdout.write("<<<mongodb_flushing>>>\n")
sys.stdout.write("average_ms %s\n" % server_status["backgroundFlushing"]["average_ms"])
sys.stdout.write("last_ms %s\n" % server_status["backgroundFlushing"]["last_ms"])
sys.stdout.write("flushed %s\n" % server_status["backgroundFlushing"]["flushes"])
section_flushing(server_status)

# Unused
# server_version = tuple(con.server_info()['version'].split('.'))
Expand Down

0 comments on commit 22e0ca3

Please sign in to comment.