Skip to content

Commit

Permalink
[docker] fix config bools, skip image stats option
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LeoCavaille committed Feb 3, 2015
1 parent 5701eaf commit 0e862f5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 6 additions & 4 deletions checks.d/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

# project
from checks import AgentCheck
from config import _is_affirmative

EVENT_TYPE = SOURCE_TYPE_NAME = 'docker'

Expand Down Expand Up @@ -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)
Expand All @@ -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)


Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions conf.d/docker.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0e862f5

Please sign in to comment.