From 0e862f5f7f16f5fc1466f4b8ebff1b4e44cac64e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Cavaill=C3=A9?= Date: Tue, 3 Feb 2015 15:19:06 -0500 Subject: [PATCH] [docker] fix config bools, skip image stats option Fixes #1342. We should always cast boolean options from the config with the `_is_affirmative` tool, otherwise you're exposed to oddities like bool('false') == True. This introduces a new option `collect_images_stats` that is enabled by default and skips the collection of metrics `docker.images.available` and `docker.images.intermediate` that sometimes is very slow through docker API if you have a lot of intermediate layer images. --- checks.d/docker.py | 10 ++++++---- conf.d/docker.yaml.example | 5 +++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/checks.d/docker.py b/checks.d/docker.py index 86af4f0c55..44aed36804 100644 --- a/checks.d/docker.py +++ b/checks.d/docker.py @@ -12,6 +12,7 @@ # project from checks import AgentCheck +from config import _is_affirmative EVENT_TYPE = SOURCE_TYPE_NAME = 'docker' @@ -127,7 +128,8 @@ def __init__(self, name, init_config, agentConfig): def check(self, instance): # Report image metrics - self._count_images(instance) + if _is_affirmative(instance.get('collect_images_stats', True)): + self._count_images(instance) # Get the list of containers and the index of their names containers, ids_to_names = self._get_and_count_containers(instance) @@ -136,7 +138,7 @@ def check(self, instance): skipped_container_ids = self._report_containers_metrics(containers, instance) # Send events from Docker API - if instance.get('collect_events', True): + if _is_affirmative(instance.get('collect_events', True)): self._process_events(instance, ids_to_names, skipped_container_ids) @@ -156,7 +158,7 @@ def _count_images(self, instance): def _get_and_count_containers(self, instance): tags = instance.get("tags", []) - with_size = instance.get('collect_container_size', False) + with_size = _is_affirmative(instance.get('collect_container_size', False)) service_check_name = 'docker.service_up' try: @@ -215,7 +217,7 @@ def _tags_match_patterns(self, tags, filters): def _report_containers_metrics(self, containers, instance): skipped_container_ids = [] - collect_uncommon_metrics = instance.get("collect_all_metrics", False) + collect_uncommon_metrics = _is_affirmative(instance.get("collect_all_metrics", False)) tags = instance.get("tags", []) # Pre-compile regex to include/exclude containers diff --git a/conf.d/docker.yaml.example b/conf.d/docker.yaml.example index 77cba87693..642cab6825 100644 --- a/conf.d/docker.yaml.example +++ b/conf.d/docker.yaml.example @@ -65,3 +65,8 @@ instances: # Collect all the available cgroups metrics. All the relevant metrics are collected by default. # # collect_all_metrics: false + + # Collect images stats + # Number of available active images and intermediate images as gauges + # + # collect_images_stats: true