Module: check_mk
Branch: master
Commit: 7488345f133b95b9edf72fa7462bbe3fc8b4d6ca
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7488345f133b95…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Thu Apr 4 12:58:47 2019 +0200
mk_mongodb: refactor on
Change-Id: I9fc365208d7c8772eefb74023123ce4d1bc642e0
---
agents/plugins/mk_mongodb | 47 ++++++++++++++++++++++++++---------------------
1 file changed, 26 insertions(+), 21 deletions(-)
diff --git a/agents/plugins/mk_mongodb b/agents/plugins/mk_mongodb
index 1817253..dda31e9 100755
--- a/agents/plugins/mk_mongodb
+++ b/agents/plugins/mk_mongodb
@@ -91,6 +91,30 @@ def sections_replica(client, server_status):
sys.stdout.write(pprint.pformat(client.admin.command("replSetGetStatus")))
+def section_chunks(client, databases):
+ sys.stdout.write("<<<mongodb_chunks>>>\n")
+ col = client.config.chunks
+ for db_name, db_data in databases.items():
+ shards = col.distinct("shard")
+ sys.stdout.write("shardcount %d\n" % len(shards))
+ for collection in db_data.get("collections"):
+ nsfilter = "%s.%s" % (db_name, collection)
+ sys.stdout.write("nscount %s %s\n" % (nsfilter,
col.find({"ns": nsfilter}).count()))
+ for shard in shards:
+ matches = col.find({"ns": nsfilter, "shard":
shard}).count()
+ sys.stdout.write("shardmatches %s#%s %s\n" % (nsfilter, shard,
matches))
+
+
+def section_locks(server_status):
+ sys.stdout.write("<<<mongodb_locks>>>\n")
+ global_lock_info = server_status.get("globalLock")
+ if global_lock_info:
+ for what in ["activeClients", "currentQueue"]:
+ if what in global_lock_info:
+ for key, value in global_lock_info[what].items():
+ sys.stdout.write("%s %s %s\n" % (what, key, value))
+
+
def main():
# might be implemented in the future..
host = None
@@ -129,28 +153,9 @@ def potentially_piggybacked_sections(client, server_status):
databases = get_database_info(client)
- sys.stdout.write("<<<mongodb_chunks>>>\n")
- col = client.config.chunks
- for db_name, db_data in databases.items():
- shards = col.distinct("shard")
- sys.stdout.write("shardcount %d\n" % len(shards))
- for collection in db_data.get("collections"):
- nsfilter = "%s.%s" % (db_name, collection)
- sys.stdout.write("nscount %s %s\n" % (nsfilter,
col.find({"ns": nsfilter}).count()))
- for shard in shards:
- sys.stdout.write("shardmatches %s#%s %s\n" % (nsfilter, shard,
- col.find({
- "ns":
nsfilter,
- "shard":
shard
- }).count()))
+ section_chunks(client, databases)
- sys.stdout.write("<<<mongodb_locks>>>\n")
- global_lock_info = server_status.get("globalLock")
- if global_lock_info:
- for what in ["activeClients", "currentQueue"]:
- if what in global_lock_info:
- for key, value in global_lock_info[what].items():
- sys.stdout.write("%s %s %s\n" % (what, key, value))
+ section_locks(server_status)
section_flushing(server_status)