Skip to content

Commit

Permalink
[docker] Add support for Docker 1.8
Browse files Browse the repository at this point in the history
Docker 1.8 adds cgroup bind mount by default ( See
https://github.com/docker/docker/blob/v1.8.0/CHANGELOG.md#runtime )

Which confuses the docker check when running in a container. This is a
tiny fix to make the docker check prefers mountpoint starting with
“/host”.
  • Loading branch information
Remi Hakim committed Aug 13, 2015
1 parent 3fb1653 commit a1df754
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions checks.d/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,34 +442,34 @@ def _get_cgroup_file(self, cgroup, container_id, filename):
def _find_cgroup(self, hierarchy, docker_root):
"""Finds the mount point for a specified cgroup hierarchy. Works with
old style and new style mounts."""
fp = None
try:
fp = open(os.path.join(docker_root, "/proc/mounts"))
with open(os.path.join(docker_root, "/proc/mounts"), 'r') as fp:
mounts = map(lambda x: x.split(), fp.read().splitlines())
finally:
if fp is not None:
fp.close()

cgroup_mounts = filter(lambda x: x[2] == "cgroup", mounts)
if len(cgroup_mounts) == 0:
raise Exception("Can't find mounted cgroups. If you run the Agent inside a container,"
" please refer to the documentation.")
# Old cgroup style
if len(cgroup_mounts) == 1:
return os.path.join(docker_root, cgroup_mounts[0][1])

candidate = None
for _, mountpoint, _, opts, _, _ in cgroup_mounts:
if hierarchy in opts:
return os.path.join(docker_root, mountpoint)
if mountpoint.startswith("/host/"):
return os.path.join(docker_root, mountpoint)
candidate = mountpoint
if candidate is not None:
return os.path.join(docker_root, candidate)
raise Exception("Can't find mounted %s cgroups." % hierarchy)


def _parse_cgroup_file(self, stat_file):
"""Parses a cgroup pseudo file for key/values."""
fp = None
self.log.debug("Opening cgroup file: %s" % stat_file)
try:
fp = open(stat_file)
return dict(map(lambda x: x.split(), fp.read().splitlines()))
with open(stat_file, 'r') as fp:
return dict(map(lambda x: x.split(), fp.read().splitlines()))
except IOError:
# It is possible that the container got stopped between the API call and now
self.log.info("Can't open %s. Metrics for this container are skipped." % stat_file)
finally:
if fp is not None:
fp.close()

0 comments on commit a1df754

Please sign in to comment.