Exemple #1
0
    def test_collector(self):
        agentConfig = {
            'api_key': 'test_apikey',
            'check_timings': True,
            'collect_ec2_tags': True,
            'collect_instance_metadata': False,
            'version': 'test',
            'tags': '',
        }

        # Run a single checks.d check as part of the collector.
        redis_config = {
            "init_config": {},
            "instances": [{"host": "localhost", "port": 6379}]
        }
        checks = [load_check('redisdb', redis_config, agentConfig)]

        c = Collector(agentConfig, [], {}, get_hostname(agentConfig))
        payload = c.run({
            'initialized_checks': checks,
            'init_failed_checks': {}
        })
        metrics = payload['metrics']

        # Check that we got a timing metric for all checks.
        timing_metrics = [m for m in metrics
            if m[0] == 'datadog.agent.check_run_time']
        all_tags = []
        for metric in timing_metrics:
            all_tags.extend(metric[3]['tags'])
        for check in checks:
            tag = "check:%s" % check.name
            assert tag in all_tags, all_tags
Exemple #2
0
    def test_collector(self):
        agentConfig = {
            "api_key": "test_apikey",
            "check_timings": True,
            "collect_ec2_tags": True,
            "collect_instance_metadata": False,
            "version": "test",
            "tags": "",
        }

        # Run a single checks.d check as part of the collector.
        redis_config = {"init_config": {}, "instances": [{"host": "localhost", "port": 6379}]}
        checks = [load_check("redisdb", redis_config, agentConfig)]

        c = Collector(agentConfig, [], {}, get_hostname(agentConfig))
        payload = c.run({"initialized_checks": checks, "init_failed_checks": {}})
        metrics = payload["metrics"]

        # Check that we got a timing metric for all checks.
        timing_metrics = [m for m in metrics if m[0] == "datadog.agent.check_run_time"]
        all_tags = []
        for metric in timing_metrics:
            all_tags.extend(metric[3]["tags"])
        for check in checks:
            tag = "check:%s" % check.name
            assert tag in all_tags, all_tags
Exemple #3
0
    def test_collector(self):
        agentConfig = {
            'api_key': 'test_apikey',
            'check_timings': True,
            'collect_ec2_tags': True,
            'collect_instance_metadata': False,
            'version': 'test',
            'tags': '',
        }

        # Run a single checks.d check as part of the collector.
        redis_config = {
            "init_config": {},
            "instances": [{
                "host": "localhost",
                "port": 6379
            }]
        }
        checks = [load_check('redisdb', redis_config, agentConfig)]

        c = Collector(agentConfig, [], {}, get_hostname(agentConfig))
        payload = c.run({
            'initialized_checks': checks,
            'init_failed_checks': {}
        })
        metrics = payload['metrics']

        # Check that we got a timing metric for all checks.
        timing_metrics = [
            m for m in metrics if m[0] == 'datadog.agent.check_run_time'
        ]
        all_tags = []
        for metric in timing_metrics:
            all_tags.extend(metric[3]['tags'])
        for check in checks:
            tag = "check:%s" % check.name
            assert tag in all_tags, all_tags
Exemple #4
0
    def test_min_collection_interval(self):

        config = {
            'instances': [{
                'host': 'localhost',
                'timeout': 1
            }],
            'init_config': {}
        }

        agentConfig = {'version': '0.1', 'api_key': 'toto'}

        # default min collection interval for that check is 20sec
        check = load_check('ntp', config, agentConfig)

        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        check.run()
        metrics = check.get_metrics()
        # No metrics should be collected as it's too early
        self.assertEquals(len(metrics), 0, metrics)

        # equivalent to time.sleep(20)
        check.last_collection_time[0] -= 20
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.last_collection_time[0] -= 3
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.DEFAULT_MIN_COLLECTION_INTERVAL = 0
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {
            'instances': [{
                'host': 'localhost',
                'timeout': 1,
                'min_collection_interval': 3
            }],
            'init_config': {}
        }
        check = load_check('ntp', config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 4
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {
            'instances': [{
                'host': 'localhost',
                'timeout': 1,
                'min_collection_interval': 12
            }],
            'init_config': {
                'min_collection_interval': 3
            }
        }
        check = load_check('ntp', config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 4
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 8
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
Exemple #5
0
    def test_min_collection_interval(self):

        config = {'instances': [{'foo': 'bar', 'timeout': 2}], 'init_config': {}}

        agentConfig = {
            'version': '0.1',
            'api_key': 'toto'
        }

        # default min collection interval for that check is 20sec
        check = load_check('ntp', config, agentConfig)

        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        
        check.run()
        metrics = check.get_metrics()
        # No metrics should be collected as it's too early
        self.assertEquals(len(metrics), 0, metrics)

        time.sleep(20)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        time.sleep(3)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.DEFAULT_MIN_COLLECTION_INTERVAL = 0
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {'instances': [{'foo': 'bar', 'timeout': 2, 'min_collection_interval':3}], 'init_config': {}}
        check = load_check('ntp', config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        time.sleep(4)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {'instances': [{'foo': 'bar', 'timeout': 2, 'min_collection_interval': 12}], 'init_config': { 'min_collection_interval':3}}
        check = load_check('ntp', config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        time.sleep(4)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        time.sleep(8)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
Exemple #6
0
    def test_min_collection_interval(self):

        config = {"instances": [{"host": "localhost", "timeout": 1}], "init_config": {}}

        agentConfig = {"version": "0.1", "api_key": "toto"}

        # default min collection interval for that check is 20sec
        check = load_check("ntp", config, agentConfig)

        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        check.run()
        metrics = check.get_metrics()
        # No metrics should be collected as it's too early
        self.assertEquals(len(metrics), 0, metrics)

        # equivalent to time.sleep(20)
        check.last_collection_time[0] -= 20
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.last_collection_time[0] -= 3
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.DEFAULT_MIN_COLLECTION_INTERVAL = 0
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {"instances": [{"host": "localhost", "timeout": 1, "min_collection_interval": 3}], "init_config": {}}
        check = load_check("ntp", config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 4
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {
            "instances": [{"host": "localhost", "timeout": 1, "min_collection_interval": 12}],
            "init_config": {"min_collection_interval": 3},
        }
        check = load_check("ntp", config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 4
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 8
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
Exemple #7
0
    def test_min_collection_interval(self):

        config = {'instances': [{'host': '0.amazon.pool.ntp.org', 'timeout': 1}], 'init_config': {}}

        agentConfig = {
            'version': '0.1',
            'api_key': 'toto'
        }

        # default min collection interval for that check is 20sec
        check = load_check('ntp', config, agentConfig)

        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        check.run()
        metrics = check.get_metrics()
        # No metrics should be collected as it's too early
        self.assertEquals(len(metrics), 0, metrics)

        # equivalent to time.sleep(20)
        check.last_collection_time[0] -= 20
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.last_collection_time[0] -= 3
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.DEFAULT_MIN_COLLECTION_INTERVAL = 0
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {'instances': [{'host': '0.amazon.pool.ntp.org', 'timeout': 1, 'min_collection_interval':3}], 'init_config': {}}
        check = load_check('ntp', config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 4
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)

        config = {'instances': [{'host': '0.amazon.pool.ntp.org', 'timeout': 1, 'min_collection_interval': 12}], 'init_config': { 'min_collection_interval':3}}
        check = load_check('ntp', config, agentConfig)
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 4
        check.run()
        metrics = check.get_metrics()
        self.assertEquals(len(metrics), 0, metrics)
        check.last_collection_time[0] -= 8
        check.run()
        metrics = check.get_metrics()
        self.assertTrue(len(metrics) > 0, metrics)