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_daemon] Report as many cgroup metrics as possible #3134

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 10 additions & 14 deletions checks.d/docker_daemon.py
Expand Up @@ -24,7 +24,6 @@
SERVICE_CHECK_NAME = 'docker.service_up'
HEALTHCHECK_SERVICE_CHECK_NAME = 'docker.container_health'
SIZE_REFRESH_RATE = 5 # Collect container sizes every 5 iterations of the check
MAX_CGROUP_LISTING_RETRIES = 3
CONTAINER_ID_RE = re.compile('[0-9a-f]{64}')

GAUGE = AgentCheck.gauge
Expand Down Expand Up @@ -182,7 +181,6 @@ def init(self):
# We configure the check with the right cgroup settings for this host
# Just needs to be done once
self._mountpoints = self.docker_util.get_mountpoints(CGROUP_METRICS)
self.cgroup_listing_retries = 0
self._latest_size_query = 0
self._filtered_containers = set()
self._disable_net_metrics = False
Expand Down Expand Up @@ -576,9 +574,17 @@ def _report_performance_metrics(self, containers_by_id):
self.log.debug(message)

def _report_cgroup_metrics(self, container, tags):
try:
for cgroup in CGROUP_METRICS:
cgroup_stat_file_failures = 0
for cgroup in CGROUP_METRICS:
try:
stat_file = self._get_cgroup_from_proc(cgroup["cgroup"], container['_pid'], cgroup['file'])
except MountException as e:
# We can't find a stat file
self.warning(str(e))
cgroup_stat_file_failures += 1
if cgroup_stat_file_failures >= len(CGROUP_METRICS):
self.warning("Couldn't find the cgroup files. Skipping the CGROUP_METRICS for now.")
else:
stats = self._parse_cgroup_file(stat_file)
if stats:
for key, (dd_key, metric_func) in cgroup['metrics'].iteritems():
Expand All @@ -597,16 +603,6 @@ def _report_cgroup_metrics(self, container, tags):
if value is not None:
metric_func(self, mname, value, tags=tags)

except MountException as ex:
if self.cgroup_listing_retries > MAX_CGROUP_LISTING_RETRIES:
raise ex
else:
self.warning("Couldn't find the cgroup files. Skipping the CGROUP_METRICS for now."
"Will retry {0} times before failing.".format(MAX_CGROUP_LISTING_RETRIES - self.cgroup_listing_retries))
self.cgroup_listing_retries += 1
else:
self.cgroup_listing_retries = 0

def _report_net_metrics(self, container, tags):
"""Find container network metrics by looking at /proc/$PID/net/dev of the container process."""
if self._disable_net_metrics:
Expand Down
2 changes: 1 addition & 1 deletion utils/dockerutil.py
Expand Up @@ -343,7 +343,7 @@ def find_cgroup_from_proc(cls, mountpoints, pid, subsys, docker_root='/'):
if os.path.exists(stat_file_path):
return os.path.join(stat_file_path, '%(file)s')

raise MountException("Cannot find Docker cgroup directory. Be sure your system is supported.")
raise MountException("Cannot find Docker '%s' cgroup directory. Be sure your system is supported." % subsys)

@classmethod
def find_cgroup_filename_pattern(cls, mountpoints, container_id):
Expand Down