Skip to content

Commit

Permalink
Merge pull request #2846 from DataDog/jaime/docker_fixyaml
Browse files Browse the repository at this point in the history
[docker_daemon] custom cgroups are per instance only. YAML updates.
  • Loading branch information
truthbk committed Sep 15, 2016
2 parents 820184a + a53c5a0 commit 74a33cf
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
9 changes: 4 additions & 5 deletions checks.d/docker_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def __init__(self, name, init_config, agentConfig, instances=None):
self._service_discovery = agentConfig.get('service_discovery') and \
agentConfig.get('service_discovery_backend') == 'docker'
self.init()
self._custom_cgroups = _is_affirmative(init_config.get('custom_cgroups', False))

def init(self):
try:
Expand Down Expand Up @@ -249,11 +248,11 @@ def check(self, instance):
self.kube_labels = {}

# containers running with custom cgroups?
custom_cgroups = _is_affirmative(instance.get('custom_cgroups', self._custom_cgroups))
custom_cgroups = _is_affirmative(instance.get('custom_cgroups', False))

# Get the list of containers and the index of their names
containers_by_id = self._get_and_count_containers(custom_cgroups)
containers_by_id = self._crawl_container_pids(containers_by_id)
containers_by_id = self._crawl_container_pids(containers_by_id, custom_cgroups)

# Send events from Docker API
if self.collect_events or self._service_discovery:
Expand Down Expand Up @@ -807,7 +806,7 @@ def _parse_blkio_metrics(self, stats):
return metrics

# proc files
def _crawl_container_pids(self, container_dict):
def _crawl_container_pids(self, container_dict, custom_cgroups=False):
"""Crawl `/proc` to find container PIDs and add them to `containers_by_id`."""
proc_path = os.path.join(self.docker_util._docker_root, 'proc')
pid_dirs = [_dir for _dir in os.listdir(proc_path) if _dir.isdigit()]
Expand Down Expand Up @@ -861,7 +860,7 @@ def _crawl_container_pids(self, container_dict):
continue
container_dict[container_id]['_pid'] = folder
container_dict[container_id]['_proc_root'] = os.path.join(proc_path, folder)
elif self._custom_cgroups: # if we match by pid that should be enough (?) - O(n) ugh!
elif custom_cgroups: # if we match by pid that should be enough (?) - O(n) ugh!
for _, container in container_dict.iteritems():
if container.get('_pid') == int(folder):
container['_proc_root'] = os.path.join(proc_path, folder)
Expand Down
12 changes: 0 additions & 12 deletions conf.d/docker.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ init_config:
# Timeout on Docker socket connection. You may have to increase it if you have many containers.
# socket_timeout: 5

# Do you use custom cgroups for your containers? Also relevant if using systemd-docker.
# Note: enabling this option modifies the way in which we inspect the containers and causes
# some overhead - if you run a high volume of containers we may timeout. Please only
# enable if absolutely necessary.
# custom_cgroups: false

instances:
# URL of the Docker daemon socket to reach the Docker API. HTTP also works.
- url: "unix://var/run/docker.sock"
Expand Down Expand Up @@ -61,12 +55,6 @@ instances:
#
# collect_events: true
#
#
# Do you use custom cgroups for this particular instance? Overrides the init_config setting.
# Note: enabling this option modifies the way in which we inspect the containers and causes
# some overhead - if you run a high volume of containers we may timeout. Please only
# enable if absolutely necessary.
# custom_cgroups: false

# Collect disk usage per container with docker.disk.size metric.
# Warning: This feature is broken in some version of Docker (such as 1.2).
Expand Down
6 changes: 6 additions & 0 deletions conf.d/docker_daemon.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ instances:
#
# collect_container_size: false

# Do you use custom cgroups for this particular instance?
# Note: enabling this option modifies the way in which we inspect the containers and causes
# some overhead - if you run a high volume of containers we may timeout. Please only
# enable if absolutely necessary.
# custom_cgroups: false

# Collect images stats
# Number of available active images and intermediate images as gauges.
# Defaults to false.
Expand Down

0 comments on commit 74a33cf

Please sign in to comment.