{"action":"created","comment":{"url":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments/39517579","id":39517579,"diff_hunk":"@@ -0,0 +1,439 @@\n+# stdlib\n+import logging\n+\n+# project\n+from tests.checks.common import AgentCheckTest\n+from utils.dockerutil import get_client, set_docker_settings, get_docker_settings, reset_docker_settings\n+\n+# 3rd party\n+from nose.plugins.attrib import attr\n+\n+log = logging.getLogger('tests')\n+\n+CONTAINERS_TO_RUN = [\n+    \"nginx\",\n+    \"redis:latest\",\n+\n+]\n+\n+@attr(requires='docker_daemon')\n+class TestCheckDockerDaemon(AgentCheckTest):\n+    CHECK_NAME = 'docker_daemon'\n+\n+    def setUp(self):\n+        self.docker_client = get_client()\n+        for c in CONTAINERS_TO_RUN:\n+            images = [i[\"RepoTags\"][0] for i in self.docker_client.images(c.split(\":\")[0]) if i[\"RepoTags\"][0].startswith(c)]\n+            if len(images) == 0:\n+                for line in self.docker_client.pull(c, stream=True):\n+                    print line\n+\n+        self.containers = []\n+        for c in CONTAINERS_TO_RUN:\n+            name = \"test-new-{0}\".format(c.replace(\":\", \"-\"))\n+            host_config = None\n+            labels = None\n+            if c == \"nginx\":\n+                host_config = {\"Memory\": 137438953472}\n+                labels = {\"label1\": \"nginx\", \"foo\": \"bar\"}\n+\n+            cont = self.docker_client.create_container(\n+                c, detach=True, name=name, host_config=host_config, labels=labels)\n+            self.containers.append(cont)\n+\n+        for c in self.containers:\n+            log.info(\"Starting container: {0}\".format(c))\n+            self.docker_client.start(c)\n+\n+\n+    def tearDown(self):\n+        for c in self.containers:\n+            log.info(\"Stopping container: {0}\".format(c))\n+            self.docker_client.remove_container(c, force=True)\n+\n+    def test_basic_config_single(self):\n+        expected_metrics = [\n+            ('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.4', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.4', 'image_tag:latest']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.mem.cache', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.rss', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.limit' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.in_use' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+        ]\n+\n+\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"collect_image_size\": True,\n+            },\n+            ],\n+        }\n+\n+        self.run_check(config, force_reload=True)\n+        for mname, tags in expected_metrics:\n+            self.assertMetric(mname, tags=tags, count=1, at_least=1)\n+\n+\n+    def test_basic_config_twice(self):\n+        expected_metrics = [\n+            ('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.cpu.system', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.cpu.system', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.cpu.user', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.cpu.user', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.io.read_bytes', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.io.read_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.io.write_bytes', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.io.write_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.cache', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.rss', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.limit' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.in_use' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.net.bytes_rcvd', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.net.bytes_rcvd', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.net.bytes_sent', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.net.bytes_sent', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx'])\n+\n+        ]\n+\n+        custom_tags = [\"extra_tag\", \"env:testing\"]\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"tags\": custom_tags,\n+            },\n+            ],\n+        }\n+\n+        self.run_check_twice(config, force_reload=True)\n+        for mname, tags in expected_metrics:\n+            expected_tags = list(custom_tags)\n+            if tags is not None:\n+                expected_tags += tags\n+            self.assertMetric(mname, tags=expected_tags, count=1, at_least=1)\n+\n+    def test_exclude_filter(self):\n+        expected_metrics = [\n+            ('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.cpu.system', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.cpu.user', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:latest', 'image_tag:1.9', 'image_tag:1.9.4']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.size', ['image_name:buildpack-deps', 'image_tag:precise']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.virtual_size', ['image_name:buildpack-deps', 'image_tag:precise']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:latest', 'image_tag:1.9', 'image_tag:1.9.4']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.io.read_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.io.write_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.net.bytes_rcvd', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.net.bytes_sent', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest'])\n+        ]\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"exclude\": [\"docker_image:nginx\"],\n+                \"collect_image_size\": True,\n+            },\n+            ],\n+        }\n+\n+        self.run_check_twice(config, force_reload=True)\n+\n+        for mname, tags in expected_metrics:\n+            self.assertMetric(mname, tags=tags, count=1, at_least=1)\n+\n+    def test_include_filter(self):\n+        expected_metrics = [\n+            ('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.cpu.system', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.cpu.user', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:latest', 'image_tag:1.9', 'image_tag:1.9.4']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.size', ['image_name:buildpack-deps', 'image_tag:precise']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.virtual_size', ['image_name:buildpack-deps', 'image_tag:precise']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:latest', 'image_tag:1.9', 'image_tag:1.9.4']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.io.read_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.io.write_bytes', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.net.bytes_rcvd', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.net.bytes_sent', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest'])\n+        ]\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"include\": [\"image_name:redis\"],\n+                \"exclude\": [\".*\"],\n+                \"collect_image_size\": True,\n+            },\n+            ],\n+        }\n+\n+        self.run_check_twice(config, force_reload=True)\n+\n+        for mname, tags in expected_metrics:\n+            self.assertMetric(mname, tags=tags, count=1, at_least=1)\n+\n+    def test_tags_options(self):\n+        expected_metrics = [\n+            ('docker.containers.running', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.containers.running', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.containers.stopped', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.containers.stopped', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.cpu.system', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.cpu.system', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.cpu.user', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.cpu.user', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.image.size', ['image_name:<none>', 'image_tag:<none>']),\n+            ('docker.image.size', ['image_name:ubuntu', 'image_tag:14.04']),\n+            ('docker.image.size', ['image_name:ruby', 'image_tag:2.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9.4', 'image_tag:1.9', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9.4', 'image_tag:1.9', 'image_tag:latest']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.io.read_bytes', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.io.read_bytes', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.io.write_bytes', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.io.write_bytes', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.mem.cache', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.mem.cache', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.mem.rss', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.mem.rss', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.mem.limit' ,[\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.mem.in_use' ,[\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.net.bytes_rcvd', ['container_command:/entrypoint.sh redis-server']),\n+            ('docker.net.bytes_rcvd', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.net.bytes_sent', [\"container_command:nginx -g 'daemon off;'\"]),\n+            ('docker.net.bytes_sent', ['container_command:/entrypoint.sh redis-server'])\n+        ]\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"performance_tags\": [\"container_command\"],\n+                \"container_tags\": [\"container_command\"],\n+                \"collect_image_size\": True,\n+            },\n+            ],\n+        }\n+\n+        self.run_check_twice(config, force_reload=True)\n+        for mname, tags in expected_metrics:\n+            self.assertMetric(mname, tags=tags, count=1, at_least=1)\n+\n+    def test_set_docker_settings(self):\n+        self.assertEqual(get_docker_settings()[\"version\"], \"auto\")\n+        cur_loc = __file__\n+        init_config = {\n+            \"api_version\": \"foobar\",\n+            \"timeout\": \"42\",\n+            \"tls_client_cert\": cur_loc,\n+            \"tls_client_key\": cur_loc,\n+            \"tls_cacert\": cur_loc,\n+            \"tls\": True\n+\n+        }\n+\n+        instance = {\n+            \"url\": \"https://foo.bar:42\",\n+        }\n+\n+        set_docker_settings(init_config, instance)\n+        client = get_client()\n+        self.assertEqual(client.verify, cur_loc)\n+        self.assertEqual(client.cert, (cur_loc, cur_loc))\n+        reset_docker_settings()\n+\n+    def test_labels_collection(self):\n+        expected_metrics = [\n+            ('docker.containers.running', ['docker_image:nginx', 'image_name:nginx', 'label1:nginx']),\n+            ('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx', 'label1:nginx']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.4', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.4', 'image_tag:latest']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.mem.cache', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx', 'label1:nginx']),\n+            ('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.rss', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx', 'label1:nginx']),\n+            ('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.limit' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx', 'label1:nginx']),\n+            ('docker.mem.in_use' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx', 'label1:nginx']),\n+        ]\n+\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"collect_labels_as_tags\": [\"label1\"],\n+                \"collect_image_size\": True,\n+            },\n+            ],\n+        }\n+\n+        self.run_check(config, force_reload=True)\n+        for mname, tags in expected_metrics:\n+            self.assertMetric(mname, tags=tags, count=1, at_least=1)\n+\n+    def test_events(self):\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+            },\n+            ],\n+        }\n+\n+        self.run_check(config, force_reload=True)\n+        self.assertEqual(len(self.events), 2)\n+\n+    def test_container_size(self):\n+        expected_metrics = [\n+            ('docker.containers.running', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.containers.running', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.containers.stopped', ['docker_image:nginx', 'image_name:nginx']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.4', 'image_tag:latest']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.1']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7', 'image_tag:1.7.12']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.0']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.7.11']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1', 'image_tag:1.9', 'image_tag:1.9.4', 'image_tag:latest']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.2']),\n+            ('docker.image.virtual_size', ['image_name:nginx', 'image_tag:1.9.3']),\n+            ('docker.image.virtual_size', ['image_name:redis', 'image_tag:latest']),\n+            ('docker.images.available', None),\n+            ('docker.images.intermediate', None),\n+            ('docker.mem.cache', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.cache', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.rss', ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.rss', ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            ('docker.mem.limit' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            ('docker.mem.in_use' ,['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            # Container size metrics\n+            (\"docker.container.size_rootfs\", ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+            (\"docker.container.size_rootfs\", ['container_name:test-new-redis-latest', 'docker_image:redis:latest', 'image_name:redis', 'image_tag:latest']),\n+            (\"docker.container.size_rw\", ['container_name:test-new-nginx', 'docker_image:nginx', 'image_name:nginx']),\n+\n+        ]\n+\n+        config = {\n+            \"init_config\": {},\n+            \"instances\": [{\n+                \"url\": \"unix://var/run/docker.sock\",\n+                \"collect_container_size\": True,\n+                \"collect_image_size\": True,\n+            },\n+            ],\n+        }\n+\n+        self.run_check(config, force_reload=True)\n+        for mname, tags in expected_metrics:\n+            self.assertMetric(mname, tags=tags, count=1, at_least=1)","path":"tests/checks/integration/test_docker_daemon.py","position":439,"original_position":439,"commit_id":"c430b41e415a93b8e5e447ee09e897fe412a6713","original_commit_id":"c430b41e415a93b8e5e447ee09e897fe412a6713","user":{"login":"remh","id":1311477,"avatar_url":"https://avatars.githubusercontent.com/u/1311477?v=3","gravatar_id":"","url":"https://api.github.com/users/remh","html_url":"https://github.com/remh","followers_url":"https://api.github.com/users/remh/followers","following_url":"https://api.github.com/users/remh/following{/other_user}","gists_url":"https://api.github.com/users/remh/gists{/gist_id}","starred_url":"https://api.github.com/users/remh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remh/subscriptions","organizations_url":"https://api.github.com/users/remh/orgs","repos_url":"https://api.github.com/users/remh/repos","events_url":"https://api.github.com/users/remh/events{/privacy}","received_events_url":"https://api.github.com/users/remh/received_events","type":"User","site_admin":false},"body":"We can't do coverage report as the test can't run on travis or circleci. I run the test locally on a machine that have more containers than the one that are spawned.\r\n","created_at":"2015-09-15T14:37:09Z","updated_at":"2015-09-15T14:37:09Z","html_url":"https://github.com/DataDog/dd-agent/pull/1908#discussion_r39517579","pull_request_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908","_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments/39517579"},"html":{"href":"https://github.com/DataDog/dd-agent/pull/1908#discussion_r39517579"},"pull_request":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908"}}},"pull_request":{"url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908","id":44814145,"html_url":"https://github.com/DataDog/dd-agent/pull/1908","diff_url":"https://github.com/DataDog/dd-agent/pull/1908.diff","patch_url":"https://github.com/DataDog/dd-agent/pull/1908.patch","issue_url":"https://api.github.com/repos/DataDog/dd-agent/issues/1908","number":1908,"state":"open","locked":false,"title":"[Docker check] V2","user":{"login":"remh","id":1311477,"avatar_url":"https://avatars.githubusercontent.com/u/1311477?v=3","gravatar_id":"","url":"https://api.github.com/users/remh","html_url":"https://github.com/remh","followers_url":"https://api.github.com/users/remh/followers","following_url":"https://api.github.com/users/remh/following{/other_user}","gists_url":"https://api.github.com/users/remh/gists{/gist_id}","starred_url":"https://api.github.com/users/remh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/remh/subscriptions","organizations_url":"https://api.github.com/users/remh/orgs","repos_url":"https://api.github.com/users/remh/repos","events_url":"https://api.github.com/users/remh/events{/privacy}","received_events_url":"https://api.github.com/users/remh/received_events","type":"User","site_admin":false},"body":"\r\nThis is a new version of the docker check, it's called docker_daemon (name can be changed).\r\nThe previous check \"docker\" is now deprecated and won't receive further support.\r\n\r\nIn terms of features, this adds:\r\n- Support for TLS connections to the daemon\r\n- New metrics: \r\n    - Network metrics\r\n    - Memory limits\r\n    - Container size (rootfs)\r\n    - Image size\r\n- Support for labels (convert them into tags). Off by default, uses a list of labels that should be converted.\r\n- Support for ECS tags: task name and task version\r\n\r\nBackward incompatible changes:\r\n\r\n    - docker.disk.size metric is renamed to docker.container.size_rw\r\n    - Old optional metrics: https://github.com/DataDog/dd-agent/blob/5.4.x/checks.d/docker.py#L29-L38 Are not collected anymore\r\n    - Old old tags are not supported anymore (e.g. `name` instead of container_name)\r\n\r\n\r\nfix #1299 #1648 #1739 #1742 \r\n","created_at":"2015-09-11T18:30:24Z","updated_at":"2015-09-15T14:37:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"55b6f3585d501714a067cae65a874d389d71f644","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908/commits","review_comments_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908/comments","review_comment_url":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/issues/1908/comments","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/c430b41e415a93b8e5e447ee09e897fe412a6713","head":{"label":"DataDog:remh/dockerv2","ref":"remh/dockerv2","sha":"c430b41e415a93b8e5e447ee09e897fe412a6713","user":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":1210071,"name":"dd-agent","full_name":"DataDog/dd-agent","owner":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/dd-agent","description":"Datadog Agent","fork":false,"url":"https://api.github.com/repos/DataDog/dd-agent","forks_url":"https://api.github.com/repos/DataDog/dd-agent/forks","keys_url":"https://api.github.com/repos/DataDog/dd-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/dd-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/dd-agent/teams","hooks_url":"https://api.github.com/repos/DataDog/dd-agent/hooks","issue_events_url":"https://api.github.com/repos/DataDog/dd-agent/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/dd-agent/events","assignees_url":"https://api.github.com/repos/DataDog/dd-agent/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/dd-agent/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/dd-agent/tags","blobs_url":"https://api.github.com/repos/DataDog/dd-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/dd-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/dd-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/dd-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/dd-agent/languages","stargazers_url":"https://api.github.com/repos/DataDog/dd-agent/stargazers","contributors_url":"https://api.github.com/repos/DataDog/dd-agent/contributors","subscribers_url":"https://api.github.com/repos/DataDog/dd-agent/subscribers","subscription_url":"https://api.github.com/repos/DataDog/dd-agent/subscription","commits_url":"https://api.github.com/repos/DataDog/dd-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/dd-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/dd-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/dd-agent/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/dd-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/dd-agent/merges","archive_url":"https://api.github.com/repos/DataDog/dd-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/dd-agent/downloads","issues_url":"https://api.github.com/repos/DataDog/dd-agent/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/dd-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/dd-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/dd-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/dd-agent/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/dd-agent/releases{/id}","created_at":"2010-12-31T03:02:47Z","updated_at":"2015-09-03T23:29:46Z","pushed_at":"2015-09-15T14:36:18Z","git_url":"git://github.com/DataDog/dd-agent.git","ssh_url":"git@github.com:DataDog/dd-agent.git","clone_url":"https://github.com/DataDog/dd-agent.git","svn_url":"https://github.com/DataDog/dd-agent","homepage":"http://docs.datadoghq.com/","size":52655,"stargazers_count":337,"watchers_count":337,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":283,"mirror_url":null,"open_issues_count":185,"forks":283,"open_issues":185,"watchers":337,"default_branch":"master"}},"base":{"label":"DataDog:master","ref":"master","sha":"279dabb35562700b96f78efce1530d7507e62a2f","user":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"repo":{"id":1210071,"name":"dd-agent","full_name":"DataDog/dd-agent","owner":{"login":"DataDog","id":365230,"avatar_url":"https://avatars.githubusercontent.com/u/365230?v=3","gravatar_id":"","url":"https://api.github.com/users/DataDog","html_url":"https://github.com/DataDog","followers_url":"https://api.github.com/users/DataDog/followers","following_url":"https://api.github.com/users/DataDog/following{/other_user}","gists_url":"https://api.github.com/users/DataDog/gists{/gist_id}","starred_url":"https://api.github.com/users/DataDog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataDog/subscriptions","organizations_url":"https://api.github.com/users/DataDog/orgs","repos_url":"https://api.github.com/users/DataDog/repos","events_url":"https://api.github.com/users/DataDog/events{/privacy}","received_events_url":"https://api.github.com/users/DataDog/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DataDog/dd-agent","description":"Datadog Agent","fork":false,"url":"https://api.github.com/repos/DataDog/dd-agent","forks_url":"https://api.github.com/repos/DataDog/dd-agent/forks","keys_url":"https://api.github.com/repos/DataDog/dd-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataDog/dd-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataDog/dd-agent/teams","hooks_url":"https://api.github.com/repos/DataDog/dd-agent/hooks","issue_events_url":"https://api.github.com/repos/DataDog/dd-agent/issues/events{/number}","events_url":"https://api.github.com/repos/DataDog/dd-agent/events","assignees_url":"https://api.github.com/repos/DataDog/dd-agent/assignees{/user}","branches_url":"https://api.github.com/repos/DataDog/dd-agent/branches{/branch}","tags_url":"https://api.github.com/repos/DataDog/dd-agent/tags","blobs_url":"https://api.github.com/repos/DataDog/dd-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataDog/dd-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataDog/dd-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataDog/dd-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataDog/dd-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/DataDog/dd-agent/languages","stargazers_url":"https://api.github.com/repos/DataDog/dd-agent/stargazers","contributors_url":"https://api.github.com/repos/DataDog/dd-agent/contributors","subscribers_url":"https://api.github.com/repos/DataDog/dd-agent/subscribers","subscription_url":"https://api.github.com/repos/DataDog/dd-agent/subscription","commits_url":"https://api.github.com/repos/DataDog/dd-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataDog/dd-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataDog/dd-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataDog/dd-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataDog/dd-agent/contents/{+path}","compare_url":"https://api.github.com/repos/DataDog/dd-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataDog/dd-agent/merges","archive_url":"https://api.github.com/repos/DataDog/dd-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataDog/dd-agent/downloads","issues_url":"https://api.github.com/repos/DataDog/dd-agent/issues{/number}","pulls_url":"https://api.github.com/repos/DataDog/dd-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/DataDog/dd-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/DataDog/dd-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataDog/dd-agent/labels{/name}","releases_url":"https://api.github.com/repos/DataDog/dd-agent/releases{/id}","created_at":"2010-12-31T03:02:47Z","updated_at":"2015-09-03T23:29:46Z","pushed_at":"2015-09-15T14:36:18Z","git_url":"git://github.com/DataDog/dd-agent.git","ssh_url":"git@github.com:DataDog/dd-agent.git","clone_url":"https://github.com/DataDog/dd-agent.git","svn_url":"https://github.com/DataDog/dd-agent","homepage":"http://docs.datadoghq.com/","size":52655,"stargazers_count":337,"watchers_count":337,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":true,"has_pages":true,"forks_count":283,"mirror_url":null,"open_issues_count":185,"forks":283,"open_issues":185,"watchers":337,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908"},"html":{"href":"https://github.com/DataDog/dd-agent/pull/1908"},"issue":{"href":"https://api.github.com/repos/DataDog/dd-agent/issues/1908"},"comments":{"href":"https://api.github.com/repos/DataDog/dd-agent/issues/1908/comments"},"review_comments":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908/comments"},"review_comment":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataDog/dd-agent/pulls/1908/commits"},"statuses":{"href":"https://api.github.com/repos/DataDog/dd-agent/statuses/c430b41e415a93b8e5e447ee09e897fe412a6713"}}}}