summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNate <nate.tade@gmail.com>2019-06-09 23:24:01 -0700
committerIlya Mashchenko <ilya@netdata.cloud>2019-06-10 09:24:01 +0300
commit32065eb9164ce0f574f41574fe29778195c5b3f3 (patch)
treed8daf53080688da51f03c7c0af76df3a7e359ad0
parent08666d90237d2e29cb2dcb19f25137f174ed8533 (diff)
dns_query_time py module: saving dns request in 'r', checking response for answer, recording '-… (#6237)
* saving dns request in 'r', checking response for answer, recording '-50' if no data in dns answer * removed time import, removes dns_start and dns_end in favor of time provided by dnspython, updated lack of answer to '-100' value, re-organized code to update query_time with only a sing q.put in finally block * fixing logic error from last commit * fixing logic error from last commit * removing divisor
-rw-r--r--collectors/python.d.plugin/dns_query_time/dns_query_time.chart.py19
1 files changed, 8 insertions, 11 deletions
diff --git a/collectors/python.d.plugin/dns_query_time/dns_query_time.chart.py b/collectors/python.d.plugin/dns_query_time/dns_query_time.chart.py
index 47a7d23f63..7fe8603147 100644
--- a/collectors/python.d.plugin/dns_query_time/dns_query_time.chart.py
+++ b/collectors/python.d.plugin/dns_query_time/dns_query_time.chart.py
@@ -8,11 +8,6 @@ from socket import getaddrinfo, gaierror
from threading import Thread
try:
- from time import monotonic as time
-except ImportError:
- from time import time
-
-try:
import dns.message
import dns.query
import dns.name
@@ -89,13 +84,15 @@ def dns_request(server_list, timeout, domains):
request = dns.message.make_query(domain, dns.rdatatype.A)
try:
- dns_start = time()
- dns.query.udp(request, ns, timeout=t)
- dns_end = time()
- query_time = round((dns_end - dns_start) * 1000)
- q.put({'_'.join(['ns', ns.replace('.', '_')]): query_time})
+ resp = dns.query.udp(request, ns, timeout=t)
+ if (resp.rcode() == dns.rcode.NOERROR and resp.answer):
+ query_time = resp.time * 1000
+ else:
+ query_time = -100
except dns.exception.Timeout:
- q.put({'_'.join(['ns', ns.replace('.', '_')]): -100})
+ query_time = -100
+ finally:
+ q.put({'_'.join(['ns', ns.replace('.', '_')]): query_time})
for server in server_list:
th = Thread(target=dns_req, args=(server, timeout, que))