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 check] V2 #1908

Merged
merged 3 commits into from
Sep 15, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require './ci/tomcat'
require './ci/varnish'
require './ci/windows'
require './ci/zookeeper'
require './ci/docker_daemon'

CLOBBER.include '**/*.pyc'

Expand Down
22 changes: 9 additions & 13 deletions checks.d/docker.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# stdlib
from collections import defaultdict
import urllib2
import urllib
import httplib
import socket
import os
import re
import socket
import time
import urllib
import urllib2
from urlparse import urlsplit
from util import json
from collections import defaultdict

# project
from checks import AgentCheck
from config import _is_affirmative
from util import json

EVENT_TYPE = SOURCE_TYPE_NAME = 'docker'

Expand Down Expand Up @@ -131,6 +131,8 @@ def __init__(self, name, init_config, agentConfig, instances=None):

def check(self, instance):
# Report image metrics
self.warning('Using the "docker" check is deprecated and will be removed'
' in a future version of the agent. Please use the "docker_daemon" one instead')
if _is_affirmative(instance.get('collect_images_stats', True)):
self._count_images(instance)

Expand Down Expand Up @@ -237,9 +239,6 @@ def _report_containers_metrics(self, containers, instance):
for name in container["Names"]:
container_tags.append(self._make_tag("name", name.lstrip("/"), instance))
for key in DOCKER_TAGS:
if key == 'Image' and ':' in container[key]:
tag = self._make_tag('image_repository', container[key].split(':')[0], instance)
container_tags.append(tag)
tag = self._make_tag(key, container[key], instance)
if tag:
container_tags.append(tag)
Expand Down Expand Up @@ -408,30 +407,27 @@ def _get_json(self, uri, params=None, multi=False):

# Cgroups

def _find_cgroup_filename_pattern(self, container_id):
def _find_cgroup_filename_pattern(self):
if self._mountpoints:
# We try with different cgroups so that it works even if only one is properly working
for mountpoint in self._mountpoints.values():
stat_file_path_lxc = os.path.join(mountpoint, "lxc")
stat_file_path_docker = os.path.join(mountpoint, "docker")
stat_file_path_coreos = os.path.join(mountpoint, "system.slice")
stat_file_path_kubernetes = os.path.join(mountpoint, container_id)

if os.path.exists(stat_file_path_lxc):
return os.path.join('%(mountpoint)s/lxc/%(id)s/%(file)s')
elif os.path.exists(stat_file_path_docker):
return os.path.join('%(mountpoint)s/docker/%(id)s/%(file)s')
elif os.path.exists(stat_file_path_coreos):
return os.path.join('%(mountpoint)s/system.slice/docker-%(id)s.scope/%(file)s')
elif os.path.exists(stat_file_path_kubernetes):
return os.path.join('%(mountpoint)s/%(id)s/%(file)s')

raise Exception("Cannot find Docker cgroup directory. Be sure your system is supported.")

def _get_cgroup_file(self, cgroup, container_id, filename):
# This can't be initialized at startup because cgroups may not be mounted yet
if not self._cgroup_filename_pattern:
self._cgroup_filename_pattern = self._find_cgroup_filename_pattern(container_id)
self._cgroup_filename_pattern = self._find_cgroup_filename_pattern()

return self._cgroup_filename_pattern % (dict(
mountpoint=self._mountpoints[cgroup],
Expand Down
Loading