Skip to content

Commit e3d0fa6

Browse files
committed
Fix conflicts
2 parents 325c6ca + 7c4716b commit e3d0fa6

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

checks.d/docker_daemon.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,11 @@ def init(self):
218218
# Other options
219219
self.collect_image_stats = _is_affirmative(instance.get('collect_images_stats', False))
220220
self.collect_container_size = _is_affirmative(instance.get('collect_container_size', False))
221+
self.collect_container_count = _is_affirmative(instance.get('collect_container_count', False))
222+
self.collect_dead_container_count = _is_affirmative(instance.get('collect_dead_container_count', False))
223+
self.collect_exited_container_count = _is_affirmative(instance.get('collect_exited_container_count', False))
224+
self.collect_volume_count = _is_affirmative(instance.get('collect_volume_count', False))
225+
self.collect_dangling_volume_count = _is_affirmative(instance.get('collect_dangling_volume_count', False))
221226
self.collect_events = _is_affirmative(instance.get('collect_events', True))
222227
self.collect_image_size = _is_affirmative(instance.get('collect_image_size', False))
223228
self.collect_disk_stats = _is_affirmative(instance.get('collect_disk_stats', False))
@@ -273,6 +278,21 @@ def check(self, instance):
273278
if self.collect_container_size:
274279
self._report_container_size(containers_by_id)
275280

281+
if self.collect_container_count:
282+
self._report_container_count_by_state(containers_by_id)
283+
284+
if self.collect_dead_container_count:
285+
self._report_container_count_by_state(containers_by_id, state="Dead")
286+
287+
if self.collect_exited_container_count:
288+
self._report_container_count_by_state(containers_by_id, state="Exited")
289+
290+
if self.collect_volume_count:
291+
self._report_volume_count()
292+
293+
if self.collect_dangling_volume_count:
294+
self._report_volume_count(filters={'dangling': True})
295+
276296
# Collect disk stats from Docker info command
277297
if self.collect_disk_stats:
278298
self._report_disk_stats()
@@ -505,7 +525,6 @@ def _report_container_size(self, containers_by_id):
505525
tags = self._get_tags(container, PERFORMANCE)
506526
m_func = FUNC_MAP[GAUGE][self.use_histogram]
507527
if "SizeRw" in container:
508-
509528
m_func(self, 'docker.container.size_rw', container['SizeRw'],
510529
tags=tags)
511530
if "SizeRootFs" in container:
@@ -542,6 +561,26 @@ def _submit_healthcheck_sc(self, container):
542561
tags = self._get_tags(container, CONTAINER)
543562
self.service_check(HEALTHCHECK_SERVICE_CHECK_NAME, status, tags=tags)
544563

564+
def _report_container_count_by_state(self, containers_by_id, state="Any"):
565+
tags = {}
566+
filterlambda = lambda x: not self._is_container_excluded(x) and state is "Any" or container["State"] is state
567+
filtered = list(filter(filterlambda, containers_by_id))
568+
tags = self._get_tags(filtered[0], PERFORMANCE)
569+
570+
m_func = FUNC_MAP[GAUGE][self.use_histogram]
571+
# Report docker.container.count if state is "Any", otherwise
572+
# report docker.container.state_STATE.count
573+
suffix = ".state_{}".format(state.lower()) if state is not "Any" else ""
574+
m_func(self, 'docker.container{}.count'.format(suffix), len(filtered), tags=tags)
575+
576+
def _report_volume_count(self, filters={}):
577+
volumes = self.docker_client.volumes(filters=filters)
578+
count = len(volumes['Volumes'])
579+
580+
m_func = FUNC_MAP[GAUGE][self.use_histogram]
581+
suffix = '.' + '-'.join(sorted(filters.keys())) if len(filters) is not 0 else ''
582+
m_func(self, 'docker.volumes{}.count'.format(suffix), count)
583+
545584
def _report_image_size(self, images):
546585
for image in images:
547586
tags = self._get_tags(image, IMAGE)

conf.d/docker_daemon.yaml.example

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,31 @@ instances:
6363
# health_service_checks: false
6464
# health_service_check_whitelist: []
6565

66+
# Collect the total container count with the docker.containers.count metric.
67+
# Defaults to false.
68+
#
69+
# collect_container_count: false
70+
71+
# Collect the count of all containers in Dead state with the docker.container.state_dead.count metric.
72+
# Defaults to false.
73+
#
74+
# collect_dead_container_count: false
75+
76+
# Collect the count of all containers in Exited state with the docker.container.state_exited.count metric.
77+
# Defaults to false.
78+
#
79+
# collect_exited_container_count: false
80+
81+
# Collect the total volume count with the docker.volumes.count metric.
82+
# Defaults to false.
83+
#
84+
# collect_volume_count: false
85+
86+
# Collect the count of all dangling volumes with the docker.volumes.dangling.count metric.
87+
# Defaults to false.
88+
#
89+
# collect_dangling_volume_count: false
90+
6691
# Collect images stats
6792
# Number of available active images and intermediate images as gauges.
6893
# Defaults to false.

tests/checks/integration/test_docker_daemon.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,11 @@ def test_labels_collection(self):
466466
"collect_labels_as_tags": ["label1"],
467467
"collect_image_size": True,
468468
"collect_images_stats": True,
469+
"collect_container_count": True,
470+
"collect_dead_container_count": True,
471+
"collect_exited_container_count": True,
472+
"collect_volume_count": True,
473+
"collect_dangling_volume_count": True,
469474
},
470475
],
471476
}

0 commit comments

Comments
 (0)