Blob Blame History Raw
From 9d1344055948aecdce77d55893eeb46e288ecbcd Mon Sep 17 00:00:00 2001
From: Jake Hunsaker <jhunsake@redhat.com>
Date: Mon, 11 Jan 2016 10:11:21 -0500
Subject: [PATCH] [docker] Gather more data and expand plugin options

This patch changes the behavior of the docker plugin and collects a bit more
data than before. In addition, it also adds 'docker-engine' to the package lists
as that is the current name of the community release of Docker.

Both 'docker version' and 'docker ps -a' output is now collected. Output from
'docker version' help to validate a given docker binary and 'ps -a' output is
collected to see all terminated, but still existing, containers present on the
system. This is kept separate from normal 'ps' output to keep it simple to only
quickly look at running containers.

The output of 'docker inspect' is now collected as well, by default only for
running containers.

Further, plugin options have been changed:

- 'logs' will now capture 'docker logs' output for all running containers.
Previously this was provided by the 'all' option which would also always include
terminated containers.

- 'all' will now cause the plugin to also include terminated containers for
'inspect' and 'logs' output. Note that by itself this option no longer captures any
additional information.

Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
---
 sos/plugins/docker.py | 49 ++++++++++++++++++++++++++++++++-----------------
 1 file changed, 32 insertions(+), 17 deletions(-)

diff --git a/sos/plugins/docker.py b/sos/plugins/docker.py
index 8c87bfa..452cf76 100644
--- a/sos/plugins/docker.py
+++ b/sos/plugins/docker.py
@@ -23,39 +23,54 @@ class Docker(Plugin):
 
     plugin_name = 'docker'
     profiles = ('virt',)
-    docker_bin = "docker"
+    docker_cmd = "docker"
 
-    option_list = [("all", "capture all container logs even the "
-                    "terminated ones", 'fast', False)]
+    option_list = [
+        ("all", "enable capture for all containers, even containers "
+            "that have terminated", 'fast', False),
+        ("logs", "capture logs for running containers",
+            'fast', False)
+    ]
 
     def setup(self):
         self.add_copy_spec([
             "/var/lib/docker/repositories-*"
         ])
 
-        self.add_cmd_output([
-            "{0} info".format(self.docker_bin),
-            "{0} ps".format(self.docker_bin),
-            "{0} images".format(self.docker_bin)
-        ])
+        for subcmd in ['info', 'ps', 'ps -a', 'images', 'version']:
+            self.add_cmd_output(
+                "{0} {1}".format(self.docker_cmd, subcmd)
+            )
+
         self.add_journal(units="docker")
 
-        ps_cmd = "{0} ps".format(self.docker_bin)
+        ps_cmd = "{0} ps -q".format(self.docker_cmd)
         if self.get_option('all'):
             ps_cmd = "{0} -a".format(ps_cmd)
 
         result = self.get_command_output(ps_cmd)
         if result['status'] == 0:
-            for line in result['output'].splitlines()[1:]:
-                container_id = line.split(" ")[0]
-                self.add_cmd_output([
-                    "{0} logs {1}".format(self.docker_bin, container_id)
-                ])
+            containers = [c for c in result['output'].splitlines()]
+            for container in containers:
+                self.add_cmd_output(
+                    "{0} inspect {1}".format(
+                        self.docker_cmd,
+                        container
+                    )
+                )
+            if self.get_option('logs'):
+                for container in containers:
+                    self.add_cmd_output(
+                        "{0} logs {1}".format(
+                            self.docker_cmd,
+                            container
+                        )
+                    )
 
 
 class RedHatDocker(Docker, RedHatPlugin):
 
-    packages = ('docker', 'docker-io')
+    packages = ('docker', 'docker-latest', 'docker-io', 'docker-engine')
 
     def setup(self):
         super(RedHatDocker, self).setup()
@@ -67,10 +82,10 @@ class RedHatDocker(Docker, RedHatPlugin):
 
 class UbuntuDocker(Docker, UbuntuPlugin):
 
-    packages = ('docker.io',)
+    packages = ('docker.io', 'docker-engine')
 
     # Name collision with another package requires docker binary rename
-    docker_bin = 'docker.io'
+    docker_cmd = 'docker.io'
 
     def setup(self):
         super(UbuntuDocker, self).setup()
-- 
2.4.11