Module: check_mk
Branch: master
Commit: 666cca35e605b6cfd14b668f17c4893ba024eec3
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=666cca35e605b6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon May 28 21:20:55 2018 +0200
6185 FIX docker_node_images: Improved performance of agent section creation
The agent section generating code has been reworked for better performance.
You will have to update the agent to get this improvement. In case you use
the old agent with the new check, you will get no image label information.
Change-Id: Ia5c3c6b8d7d34729b8961273c08cc09b193ec343
---
.werks/6185 | 13 +++++++++++++
agents/check_mk_agent.linux | 12 ++++++------
inventory/docker_node_images | 30 ++++++++++++++----------------
3 files changed, 33 insertions(+), 22 deletions(-)
diff --git a/.werks/6185 b/.werks/6185
new file mode 100644
index 0000000..168bcd3
--- /dev/null
+++ b/.werks/6185
@@ -0,0 +1,13 @@
+Title: docker_node_images: Improved performance of agent section creation
+Level: 1
+Component: inv
+Class: fix
+Compatible: compat
+Edition: cre
+State: unknown
+Version: 1.6.0i1
+Date: 1527535164
+
+The agent section generating code has been reworked for better performance.
+You will have to update the agent to get this improvement. In case you use
+the old agent with the new check, you will get no image label information.
diff --git a/agents/check_mk_agent.linux b/agents/check_mk_agent.linux
index 14696be..506e198 100755
--- a/agents/check_mk_agent.linux
+++ b/agents/check_mk_agent.linux
@@ -1003,12 +1003,12 @@ if type docker > /dev/null 2>&1 && [ -z
"$MK_IS_PIGGYBACKED" ]; then
echo "<<<docker_node_images>>>"
echo "[[[images]]]"
- docker images --all --format "{{json .}}"
- for image in $(docker images --all --format "{{.Repository}}:{{.Tag}}");
- do
- echo "[[[images_labels:$image]]]"
- docker image inspect --format "{{json .Config.Labels}}"
"$image"
- done
+ docker images --format "{{json .}}"
+
+ echo "[[[image_labels]]]"
+ IMAGE_IDS=$(docker images --format '{{.ID}}')
+ docker image inspect --format "[ {{json .Id}}, {{json .Config.Labels}} ]"
"$IMAGE_IDS"
+
echo "[[[containers]]]"
docker container ls --all --format "{{json .}}"
diff --git a/inventory/docker_node_images b/inventory/docker_node_images
index a260e55..fcb99b7 100644
--- a/inventory/docker_node_images
+++ b/inventory/docker_node_images
@@ -37,15 +37,14 @@ def _parse_docker_node_images(info):
data = json.loads(" ".join(line))
if section_name == "images" and data:
- parsed.setdefault((data["Repository"], data["Tag"]),
data)
+ parsed.setdefault(data["ID"], data)
- elif section_name.startswith("images_labels"):
- parts = section_name.split(":", 2)
- if len(parts) == 3:
- repository, tag = parts[1:]
- image = parsed.get((repository, tag))
- if image is not None and data:
- image.setdefault("__labels__", data)
+ elif section_name == "images_labels":
+ if len(data) == 2:
+ image_id, labels = data
+ image = parsed.get(image_id)
+ if image is not None and labels:
+ image.setdefault("__labels__", labels)
elif section_name == "containers":
image_name = data["Image"]
@@ -66,21 +65,20 @@ def inv_docker_node_images(info, inventory_tree, status_data_tree):
inv_node = inventory_tree.get_list(path)
status_node = status_data_tree.get_list(path)
- for (repo, tag), image in sorted(parsed.iteritems()):
- id_ = image["ID"]
+ for image_id, image in sorted(parsed.iteritems()):
inv_node.append({
- "repository" : repo,
- "tag" : tag,
- "id" : id_,
+ "repository" : image["Repository"],
+ "tag" : image["Tag"],
+ "id" : image_id,
"creation" : image["CreatedAt"],
"size" : image["VirtualSize"],
"labels" :
_format_labels(image.get("__labels__", {}).items()),
})
status_node.append({
- "repository" : repo,
- "tag" : tag,
- "id" : id_,
+ "repository" : image["Repository"],
+ "tag" : image["Tag"],
+ "id" : image_id,
"amount_containers" : len(image.get("__containers__",
[])),
})