From 9e2c639f88c20c14fc2d35355d78bd808b14b9b7 Mon Sep 17 00:00:00 2001 From: Markus Fischbacher Date: Fri, 18 Sep 2026 11:30:57 +0200 Subject: [PATCH 1/4] Add gauges for DNS connection status in DNSCheck --- dns_check/datadog_checks/dns_check/dns_check.py | 8 ++++++++ dns_check/metadata.csv | 2 ++ 2 files changed, 10 insertions(+) diff --git a/dns_check/datadog_checks/dns_check/dns_check.py b/dns_check/datadog_checks/dns_check/dns_check.py index 6ca481fe16994..3b6977cc7cf5c 100644 --- a/dns_check/datadog_checks/dns_check/dns_check.py +++ b/dns_check/datadog_checks/dns_check/dns_check.py @@ -95,6 +95,8 @@ def check(self, _): if response_time > 0: self.gauge('dns.response_time', response_time, tags=tags) self.log.debug('Resolved hostname: %s', self.hostname) + self.gauge("dns.can_connect", 1, tags=tags) + self.gauge("dns.cant_connect", 0, tags=tags) self.report_as_service_check(AgentCheck.OK) def _check_answer(self, answer): @@ -123,4 +125,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, From e4898ecf8f2f204529a9e14609a361d7bd8d7315 Mon Sep 17 00:00:00 2001 From: Markus Fischbacher Date: Fri, 18 Sep 2026 12:12:26 +0200 Subject: [PATCH 2/4] Add metrics for DNS connection status in tests --- dns_check/tests/common.py | 2 ++ dns_check/tests/test_dns_check.py | 6 ++++++ 2 files changed, 8 insertions(+) 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() From 2df81729e12095f87d5a340dab5f63c1d6902ac6 Mon Sep 17 00:00:00 2001 From: Markus Fischbacher Date: Fri, 18 Sep 2026 12:17:06 +0200 Subject: [PATCH 3/4] Add changelog entry for DNS check connection status metrics --- dns_check/changelog.d/25271.added | 1 + 1 file changed, 1 insertion(+) create mode 100644 dns_check/changelog.d/25271.added 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 From a6df327ebcd0797e193de24e9514d541c24b25d6 Mon Sep 17 00:00:00 2001 From: Markus Fischbacher Date: Fri, 18 Sep 2026 12:22:08 +0200 Subject: [PATCH 4/4] removed duplicate gauge send --- dns_check/datadog_checks/dns_check/dns_check.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/dns_check/datadog_checks/dns_check/dns_check.py b/dns_check/datadog_checks/dns_check/dns_check.py index 3b6977cc7cf5c..12a9823865c37 100644 --- a/dns_check/datadog_checks/dns_check/dns_check.py +++ b/dns_check/datadog_checks/dns_check/dns_check.py @@ -95,8 +95,6 @@ def check(self, _): if response_time > 0: self.gauge('dns.response_time', response_time, tags=tags) self.log.debug('Resolved hostname: %s', self.hostname) - self.gauge("dns.can_connect", 1, tags=tags) - self.gauge("dns.cant_connect", 0, tags=tags) self.report_as_service_check(AgentCheck.OK) def _check_answer(self, answer):