Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docker] Fix pid retrieval #2847

Merged
merged 1 commit into from
Sep 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions checks.d/docker_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,17 @@ def _parse_blkio_metrics(self, stats):
metrics['io_write'] += int(line.split()[2])
return metrics

def _is_container_cgroup(self, line, selinux_policy):
if line[1] not in ('cpu,cpuacct', 'cpuacct,cpu', 'cpuacct') or line[2] == '/docker-daemon':
return False
if 'docker' in line[2]: # general case
return True
if 'docker' in selinux_policy: # selinux
return True
if line[2].startswith('/') and re.match(CONTAINER_ID_RE, line[2][1:]): # kubernetes
return True
return False

# proc files
def _crawl_container_pids(self, container_dict):
"""Crawl `/proc` to find container PIDs and add them to `containers_by_id`."""
Expand Down Expand Up @@ -846,8 +857,7 @@ def _crawl_container_pids(self, container_dict):

try:
for line in content:
if line[1] in ('cpu,cpuacct', 'cpuacct,cpu', 'cpuacct') and \
('docker' in line[2] or 'docker' in selinux_policy):
if self._is_container_cgroup(line, selinux_policy):
cpuacct = line[2]
break
else:
Expand Down