We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Cannot find Docker cgroup directory. Be sure your system is supported.
Running docker 1.8.3 on Ubuntu 14.04. Running dd-agent under Kubernetes.  Kept getting the error message in the subject until I made a patch to 5.6.2 https://gist.github.com/bakins/00cc12f26e2947af6679

I am not running the packaged version of docker (ie, the deb) - just the binary (issues with Kubernetes for me using packaged version).


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `utils/dockerutil.py`
Content:
```
1 # stdlib
2 import os
3 
4 # 3rd party
5 from docker import Client
6 from docker import tls
7 
8 
9 class MountException(Exception):
10     pass
11 
12 # Default docker client settings
13 DEFAULT_TIMEOUT = 5
14 DEFAULT_VERSION = 'auto'
15 
16 _docker_client_settings = {"version": DEFAULT_VERSION}
17 
18 
19 def get_docker_settings():
20     global _docker_client_settings
21     return _docker_client_settings
22 
23 
24 def reset_docker_settings():
25     global _docker_client_settings
26     _docker_client_settings = {"version": DEFAULT_VERSION}
27 
28 
29 def set_docker_settings(init_config, instance):
30     global _docker_client_settings
31     _docker_client_settings = {
32         "version": init_config.get('api_version', DEFAULT_VERSION),
33         "base_url": instance.get("url"),
34         "timeout": int(init_config.get('timeout', DEFAULT_TIMEOUT)),
35     }
36 
37     if init_config.get('tls', False):
38         client_cert_path = init_config.get('tls_client_cert')
39         client_key_path = init_config.get('tls_client_key')
40         cacert = init_config.get('tls_cacert')
41         verify = init_config.get('tls_verify')
42 
43         client_cert = None
44         if client_cert_path is not None and client_key_path is not None:
45             client_cert = (client_cert_path, client_key_path)
46 
47         verify = verify if verify is not None else cacert
48         tls_config = tls.TLSConfig(client_cert=client_cert, verify=verify)
49         _docker_client_settings["tls"] = tls_config
50 
51 
52 def get_client():
53     return Client(**_docker_client_settings)
54 
55 
56 def find_cgroup(hierarchy, docker_root):
57         """Find the mount point for a specified cgroup hierarchy.
58 
59         Works with old style and new style mounts.
60         """
61         with open(os.path.join(docker_root, "/proc/mounts"), 'r') as fp:
62             mounts = map(lambda x: x.split(), fp.read().splitlines())
63         cgroup_mounts = filter(lambda x: x[2] == "cgroup", mounts)
64         if len(cgroup_mounts) == 0:
65             raise Exception(
66                 "Can't find mounted cgroups. If you run the Agent inside a container,"
67                 " please refer to the documentation.")
68         # Old cgroup style
69         if len(cgroup_mounts) == 1:
70             return os.path.join(docker_root, cgroup_mounts[0][1])
71 
72         candidate = None
73         for _, mountpoint, _, opts, _, _ in cgroup_mounts:
74             if hierarchy in opts:
75                 if mountpoint.startswith("/host/"):
76                     return os.path.join(docker_root, mountpoint)
77                 candidate = mountpoint
78 
79         if candidate is not None:
80             return os.path.join(docker_root, candidate)
81         raise Exception("Can't find mounted %s cgroups." % hierarchy)
82 
83 
84 def find_cgroup_filename_pattern(mountpoints, container_id):
85     # We try with different cgroups so that it works even if only one is properly working
86     for mountpoint in mountpoints.itervalues():
87         stat_file_path_lxc = os.path.join(mountpoint, "lxc")
88         stat_file_path_docker = os.path.join(mountpoint, "docker")
89         stat_file_path_coreos = os.path.join(mountpoint, "system.slice")
90         stat_file_path_kubernetes = os.path.join(mountpoint, container_id)
91         stat_file_path_kubernetes_docker = os.path.join(mountpoint, "system", "docker", container_id)
92 
93         if os.path.exists(stat_file_path_lxc):
94             return os.path.join('%(mountpoint)s/lxc/%(id)s/%(file)s')
95         elif os.path.exists(stat_file_path_docker):
96             return os.path.join('%(mountpoint)s/docker/%(id)s/%(file)s')
97         elif os.path.exists(stat_file_path_coreos):
98             return os.path.join('%(mountpoint)s/system.slice/docker-%(id)s.scope/%(file)s')
99         elif os.path.exists(stat_file_path_kubernetes):
100             return os.path.join('%(mountpoint)s/%(id)s/%(file)s')
101         elif os.path.exists(stat_file_path_kubernetes_docker):
102             return os.path.join('%(mountpoint)s/system/docker/%(id)s/%(file)s')
103 
104     raise MountException("Cannot find Docker cgroup directory. Be sure your system is supported.")
105 
106 
107 def image_tag_extractor(entity, key):
108     if "Image" in entity:
109         split = entity["Image"].split(":")
110         if len(split) <= key:
111             return None
112         elif len(split) > 2:
113             # if the repo is in the image name and has the form 'docker.clearbit:5000'
114             # the split will be like [repo_url, repo_port/image_name, image_tag]. Let's avoid that
115             split = [':'.join(split[:-1]), split[-1]]
116         return [split[key]]
117     if "RepoTags" in entity:
118         splits = [el.split(":") for el in entity["RepoTags"]]
119         tags = set()
120         for split in splits:
121             if len(split) > 2:
122                 split = [':'.join(split[:-1]), split[-1]]
123             if len(split) > key:
124                 tags.add(split[key])
125         if len(tags) > 0:
126             return list(tags)
127     return None
128 
129 
130 def container_name_extractor(co):
131     names = co.get('Names', [])
132     if names is not None:
133         # we sort the list to make sure that a docker API update introducing
134         # new names with a single "/" won't make us report dups.
135         names = sorted(names)
136         for name in names:
137             # the leading "/" is legit, if there's another one it means the name is actually an alias
138             if name.count('/') <= 1:
139                 return [str(name).lstrip('/')]
140     return co.get('Id')[:11]
141
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/utils/dockerutil.py b/utils/dockerutil.py
--- a/utils/dockerutil.py
+++ b/utils/dockerutil.py
@@ -89,6 +89,7 @@
         stat_file_path_coreos = os.path.join(mountpoint, "system.slice")
         stat_file_path_kubernetes = os.path.join(mountpoint, container_id)
         stat_file_path_kubernetes_docker = os.path.join(mountpoint, "system", "docker", container_id)
+        stat_file_path_docker_daemon = os.path.join(mountpoint, "docker-daemon", "docker", container_id)
 
         if os.path.exists(stat_file_path_lxc):
             return os.path.join('%(mountpoint)s/lxc/%(id)s/%(file)s')
@@ -100,6 +101,9 @@
             return os.path.join('%(mountpoint)s/%(id)s/%(file)s')
         elif os.path.exists(stat_file_path_kubernetes_docker):
             return os.path.join('%(mountpoint)s/system/docker/%(id)s/%(file)s')
+        elif os.path.exists(stat_file_path_docker_daemon):
+            return os.path.join('%(mountpoint)s/docker-daemon/docker/%(id)s/%(file)s')
+
 
     raise MountException("Cannot find Docker cgroup directory. Be sure your system is supported.")

{"golden_diff": "diff --git a/utils/dockerutil.py b/utils/dockerutil.py\n--- a/utils/dockerutil.py\n+++ b/utils/dockerutil.py\n@@ -89,6 +89,7 @@\n         stat_file_path_coreos = os.path.join(mountpoint, \"system.slice\")\n         stat_file_path_kubernetes = os.path.join(mountpoint, container_id)\n         stat_file_path_kubernetes_docker = os.path.join(mountpoint, \"system\", \"docker\", container_id)\n+        stat_file_path_docker_daemon = os.path.join(mountpoint, \"docker-daemon\", \"docker\", container_id)\n \n         if os.path.exists(stat_file_path_lxc):\n             return os.path.join('%(mountpoint)s/lxc/%(id)s/%(file)s')\n@@ -100,6 +101,9 @@\n             return os.path.join('%(mountpoint)s/%(id)s/%(file)s')\n         elif os.path.exists(stat_file_path_kubernetes_docker):\n             return os.path.join('%(mountpoint)s/system/docker/%(id)s/%(file)s')\n+        elif os.path.exists(stat_file_path_docker_daemon):\n+            return os.path.join('%(mountpoint)s/docker-daemon/docker/%(id)s/%(file)s')\n+\n \n     raise MountException(\"Cannot find Docker cgroup directory. Be sure your system is supported.\")\n", "issue": "Cannot find Docker cgroup directory. Be sure your system is supported.\nRunning docker 1.8.3 on Ubuntu 14.04. Running dd-agent under Kubernetes.  Kept getting the error message in the subject until I made a patch to 5.6.2 https://gist.github.com/bakins/00cc12f26e2947af6679\n\nI am not running the packaged version of docker (ie, the deb) - just the binary (issues with Kubernetes for me using packaged version).\n\n", "before_files": [{"content": "# stdlib\nimport os\n\n# 3rd party\nfrom docker import Client\nfrom docker import tls\n\n\nclass MountException(Exception):\n    pass\n\n# Default docker client settings\nDEFAULT_TIMEOUT = 5\nDEFAULT_VERSION = 'auto'\n\n_docker_client_settings = {\"version\": DEFAULT_VERSION}\n\n\ndef get_docker_settings():\n    global _docker_client_settings\n    return _docker_client_settings\n\n\ndef reset_docker_settings():\n    global _docker_client_settings\n    _docker_client_settings = {\"version\": DEFAULT_VERSION}\n\n\ndef set_docker_settings(init_config, instance):\n    global _docker_client_settings\n    _docker_client_settings = {\n        \"version\": init_config.get('api_version', DEFAULT_VERSION),\n        \"base_url\": instance.get(\"url\"),\n        \"timeout\": int(init_config.get('timeout', DEFAULT_TIMEOUT)),\n    }\n\n    if init_config.get('tls', False):\n        client_cert_path = init_config.get('tls_client_cert')\n        client_key_path = init_config.get('tls_client_key')\n        cacert = init_config.get('tls_cacert')\n        verify = init_config.get('tls_verify')\n\n        client_cert = None\n        if client_cert_path is not None and client_key_path is not None:\n            client_cert = (client_cert_path, client_key_path)\n\n        verify = verify if verify is not None else cacert\n        tls_config = tls.TLSConfig(client_cert=client_cert, verify=verify)\n        _docker_client_settings[\"tls\"] = tls_config\n\n\ndef get_client():\n    return Client(**_docker_client_settings)\n\n\ndef find_cgroup(hierarchy, docker_root):\n        \"\"\"Find the mount point for a specified cgroup hierarchy.\n\n        Works with old style and new style mounts.\n        \"\"\"\n        with open(os.path.join(docker_root, \"/proc/mounts\"), 'r') as fp:\n            mounts = map(lambda x: x.split(), fp.read().splitlines())\n        cgroup_mounts = filter(lambda x: x[2] == \"cgroup\", mounts)\n        if len(cgroup_mounts) == 0:\n            raise Exception(\n                \"Can't find mounted cgroups. If you run the Agent inside a container,\"\n                \" please refer to the documentation.\")\n        # Old cgroup style\n        if len(cgroup_mounts) == 1:\n            return os.path.join(docker_root, cgroup_mounts[0][1])\n\n        candidate = None\n        for _, mountpoint, _, opts, _, _ in cgroup_mounts:\n            if hierarchy in opts:\n                if mountpoint.startswith(\"/host/\"):\n                    return os.path.join(docker_root, mountpoint)\n                candidate = mountpoint\n\n        if candidate is not None:\n            return os.path.join(docker_root, candidate)\n        raise Exception(\"Can't find mounted %s cgroups.\" % hierarchy)\n\n\ndef find_cgroup_filename_pattern(mountpoints, container_id):\n    # We try with different cgroups so that it works even if only one is properly working\n    for mountpoint in mountpoints.itervalues():\n        stat_file_path_lxc = os.path.join(mountpoint, \"lxc\")\n        stat_file_path_docker = os.path.join(mountpoint, \"docker\")\n        stat_file_path_coreos = os.path.join(mountpoint, \"system.slice\")\n        stat_file_path_kubernetes = os.path.join(mountpoint, container_id)\n        stat_file_path_kubernetes_docker = os.path.join(mountpoint, \"system\", \"docker\", container_id)\n\n        if os.path.exists(stat_file_path_lxc):\n            return os.path.join('%(mountpoint)s/lxc/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_docker):\n            return os.path.join('%(mountpoint)s/docker/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_coreos):\n            return os.path.join('%(mountpoint)s/system.slice/docker-%(id)s.scope/%(file)s')\n        elif os.path.exists(stat_file_path_kubernetes):\n            return os.path.join('%(mountpoint)s/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_kubernetes_docker):\n            return os.path.join('%(mountpoint)s/system/docker/%(id)s/%(file)s')\n\n    raise MountException(\"Cannot find Docker cgroup directory. Be sure your system is supported.\")\n\n\ndef image_tag_extractor(entity, key):\n    if \"Image\" in entity:\n        split = entity[\"Image\"].split(\":\")\n        if len(split) <= key:\n            return None\n        elif len(split) > 2:\n            # if the repo is in the image name and has the form 'docker.clearbit:5000'\n            # the split will be like [repo_url, repo_port/image_name, image_tag]. Let's avoid that\n            split = [':'.join(split[:-1]), split[-1]]\n        return [split[key]]\n    if \"RepoTags\" in entity:\n        splits = [el.split(\":\") for el in entity[\"RepoTags\"]]\n        tags = set()\n        for split in splits:\n            if len(split) > 2:\n                split = [':'.join(split[:-1]), split[-1]]\n            if len(split) > key:\n                tags.add(split[key])\n        if len(tags) > 0:\n            return list(tags)\n    return None\n\n\ndef container_name_extractor(co):\n    names = co.get('Names', [])\n    if names is not None:\n        # we sort the list to make sure that a docker API update introducing\n        # new names with a single \"/\" won't make us report dups.\n        names = sorted(names)\n        for name in names:\n            # the leading \"/\" is legit, if there's another one it means the name is actually an alias\n            if name.count('/') <= 1:\n                return [str(name).lstrip('/')]\n    return co.get('Id')[:11]\n", "path": "utils/dockerutil.py"}], "after_files": [{"content": "# stdlib\nimport os\n\n# 3rd party\nfrom docker import Client\nfrom docker import tls\n\n\nclass MountException(Exception):\n    pass\n\n# Default docker client settings\nDEFAULT_TIMEOUT = 5\nDEFAULT_VERSION = 'auto'\n\n_docker_client_settings = {\"version\": DEFAULT_VERSION}\n\n\ndef get_docker_settings():\n    global _docker_client_settings\n    return _docker_client_settings\n\n\ndef reset_docker_settings():\n    global _docker_client_settings\n    _docker_client_settings = {\"version\": DEFAULT_VERSION}\n\n\ndef set_docker_settings(init_config, instance):\n    global _docker_client_settings\n    _docker_client_settings = {\n        \"version\": init_config.get('api_version', DEFAULT_VERSION),\n        \"base_url\": instance.get(\"url\"),\n        \"timeout\": int(init_config.get('timeout', DEFAULT_TIMEOUT)),\n    }\n\n    if init_config.get('tls', False):\n        client_cert_path = init_config.get('tls_client_cert')\n        client_key_path = init_config.get('tls_client_key')\n        cacert = init_config.get('tls_cacert')\n        verify = init_config.get('tls_verify')\n\n        client_cert = None\n        if client_cert_path is not None and client_key_path is not None:\n            client_cert = (client_cert_path, client_key_path)\n\n        verify = verify if verify is not None else cacert\n        tls_config = tls.TLSConfig(client_cert=client_cert, verify=verify)\n        _docker_client_settings[\"tls\"] = tls_config\n\n\ndef get_client():\n    return Client(**_docker_client_settings)\n\n\ndef find_cgroup(hierarchy, docker_root):\n        \"\"\"Find the mount point for a specified cgroup hierarchy.\n\n        Works with old style and new style mounts.\n        \"\"\"\n        with open(os.path.join(docker_root, \"/proc/mounts\"), 'r') as fp:\n            mounts = map(lambda x: x.split(), fp.read().splitlines())\n        cgroup_mounts = filter(lambda x: x[2] == \"cgroup\", mounts)\n        if len(cgroup_mounts) == 0:\n            raise Exception(\n                \"Can't find mounted cgroups. If you run the Agent inside a container,\"\n                \" please refer to the documentation.\")\n        # Old cgroup style\n        if len(cgroup_mounts) == 1:\n            return os.path.join(docker_root, cgroup_mounts[0][1])\n\n        candidate = None\n        for _, mountpoint, _, opts, _, _ in cgroup_mounts:\n            if hierarchy in opts:\n                if mountpoint.startswith(\"/host/\"):\n                    return os.path.join(docker_root, mountpoint)\n                candidate = mountpoint\n\n        if candidate is not None:\n            return os.path.join(docker_root, candidate)\n        raise Exception(\"Can't find mounted %s cgroups.\" % hierarchy)\n\n\ndef find_cgroup_filename_pattern(mountpoints, container_id):\n    # We try with different cgroups so that it works even if only one is properly working\n    for mountpoint in mountpoints.itervalues():\n        stat_file_path_lxc = os.path.join(mountpoint, \"lxc\")\n        stat_file_path_docker = os.path.join(mountpoint, \"docker\")\n        stat_file_path_coreos = os.path.join(mountpoint, \"system.slice\")\n        stat_file_path_kubernetes = os.path.join(mountpoint, container_id)\n        stat_file_path_kubernetes_docker = os.path.join(mountpoint, \"system\", \"docker\", container_id)\n        stat_file_path_docker_daemon = os.path.join(mountpoint, \"docker-daemon\", \"docker\", container_id)\n\n        if os.path.exists(stat_file_path_lxc):\n            return os.path.join('%(mountpoint)s/lxc/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_docker):\n            return os.path.join('%(mountpoint)s/docker/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_coreos):\n            return os.path.join('%(mountpoint)s/system.slice/docker-%(id)s.scope/%(file)s')\n        elif os.path.exists(stat_file_path_kubernetes):\n            return os.path.join('%(mountpoint)s/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_kubernetes_docker):\n            return os.path.join('%(mountpoint)s/system/docker/%(id)s/%(file)s')\n        elif os.path.exists(stat_file_path_docker_daemon):\n            return os.path.join('%(mountpoint)s/docker-daemon/docker/%(id)s/%(file)s')\n\n\n    raise MountException(\"Cannot find Docker cgroup directory. Be sure your system is supported.\")\n\n\ndef image_tag_extractor(entity, key):\n    if \"Image\" in entity:\n        split = entity[\"Image\"].split(\":\")\n        if len(split) <= key:\n            return None\n        elif len(split) > 2:\n            # if the repo is in the image name and has the form 'docker.clearbit:5000'\n            # the split will be like [repo_url, repo_port/image_name, image_tag]. Let's avoid that\n            split = [':'.join(split[:-1]), split[-1]]\n        return [split[key]]\n    if \"RepoTags\" in entity:\n        splits = [el.split(\":\") for el in entity[\"RepoTags\"]]\n        tags = set()\n        for split in splits:\n            if len(split) > 2:\n                split = [':'.join(split[:-1]), split[-1]]\n            if len(split) > key:\n                tags.add(split[key])\n        if len(tags) > 0:\n            return list(tags)\n    return None\n\n\ndef container_name_extractor(co):\n    names = co.get('Names', [])\n    if names is not None:\n        # we sort the list to make sure that a docker API update introducing\n        # new names with a single \"/\" won't make us report dups.\n        names = sorted(names)\n        for name in names:\n            # the leading \"/\" is legit, if there's another one it means the name is actually an alias\n            if name.count('/') <= 1:\n                return [str(name).lstrip('/')]\n    return co.get('Id')[:11]\n", "path": "utils/dockerutil.py"}]}