diff --git a/dns_check/changelog.d/25271.added b/dns_check/changelog.d/25271.added new file mode 100644 index 0000000000000..daf87cfa7821a --- /dev/null +++ b/dns_check/changelog.d/25271.added @@ -0,0 +1 @@ +Added metrics for connection dns_check status. \ No newline at end of file diff --git a/dns_check/datadog_checks/dns_check/dns_check.py b/dns_check/datadog_checks/dns_check/dns_check.py index 6ca481fe16994..12a9823865c37 100644 --- a/dns_check/datadog_checks/dns_check/dns_check.py +++ b/dns_check/datadog_checks/dns_check/dns_check.py @@ -123,4 +123,10 @@ def _get_tags(self): def report_as_service_check(self, status, msg=None): tags = self._get_tags() + if status != AgentCheck.OK: + self.gauge("dns.can_connect", 0, tags=tags) + self.gauge("dns.cant_connect", 1, tags=tags) + else: + self.gauge("dns.can_connect", 1, tags=tags) + self.gauge("dns.cant_connect", 0, tags=tags) self.service_check(self.SERVICE_CHECK_NAME, status, tags=tags, message=msg) diff --git a/dns_check/metadata.csv b/dns_check/metadata.csv index ca05f2ab28631..a5dcb4b960df5 100644 --- a/dns_check/metadata.csv +++ b/dns_check/metadata.csv @@ -1,2 +1,4 @@ metric_name,metric_type,interval,unit_name,per_unit_name,description,orientation,integration,short_name,curated_metric dns.response_time,gauge,,second,,"The response time for DNS query for a given record, tagged by hostname, e.g. 'hostname:example.com'.",-1,dns,dns resp time, +dns.can_connect,gauge,,,"","Indicates if the DNS check can connect to the DNS server (1 for yes, 0 for no).",0,dns,dns can connect, +dns.cant_connect,gauge,,,"","Indicates if the DNS check cannot connect to the DNS server (1 for yes, 0 for no).",0,dns,dns cant connect, diff --git a/dns_check/tests/common.py b/dns_check/tests/common.py index 27623fc1ca186..9d2e5089133fe 100644 --- a/dns_check/tests/common.py +++ b/dns_check/tests/common.py @@ -56,5 +56,7 @@ def _test_check(aggregator): aggregator.assert_metric('dns.response_time') + aggregator.assert_metric('dns.can_connect') + aggregator.assert_metric('dns.cant_connect') aggregator.assert_all_metrics_covered() aggregator.assert_metrics_using_metadata(get_metadata_metrics()) diff --git a/dns_check/tests/test_dns_check.py b/dns_check/tests/test_dns_check.py index fe012d56da7a2..8a6dc59b53a6e 100644 --- a/dns_check/tests/test_dns_check.py +++ b/dns_check/tests/test_dns_check.py @@ -65,6 +65,8 @@ def test_success(mocked_query, mocked_time, aggregator, instance, tags): integration.check({}) aggregator.assert_service_check(DNSCheck.SERVICE_CHECK_NAME, status=DNSCheck.OK, tags=tags, count=1) aggregator.assert_metric('dns.response_time', tags=tags, count=1, value=1) + aggregator.assert_metric('dns.can_connect', tags=tags, count=1, value=1) + aggregator.assert_metric('dns.cant_connect', tags=tags, count=1, value=0) # Assert coverage for this check on this instance aggregator.assert_all_metrics_covered() @@ -79,6 +81,8 @@ def test_success_nxdomain(mocked_query, mocked_time, aggregator): tags = ['instance:nxdomain', 'nameserver:127.0.0.1', 'resolved_hostname:www.example.org', 'record_type:NXDOMAIN'] aggregator.assert_service_check(DNSCheck.SERVICE_CHECK_NAME, status=DNSCheck.OK, tags=tags, count=1) aggregator.assert_metric('dns.response_time', tags=tags, count=1, value=1) + aggregator.assert_metric('dns.can_connect', tags=tags, count=1, value=1) + aggregator.assert_metric('dns.cant_connect', tags=tags, count=1, value=0) # Assert coverage for this check on this instance aggregator.assert_all_metrics_covered() @@ -100,6 +104,8 @@ def test_default_timeout(mocked_query, mocked_time, aggregator): count=1, message="DNS resolution of www.example.org timed out", ) + aggregator.assert_metric('dns.can_connect', tags=tags, count=1, value=0) + aggregator.assert_metric('dns.cant_connect', tags=tags, count=1, value=1) # Assert coverage for this check on this instance aggregator.assert_all_metrics_covered()