integrations/Dns_Query/markdown/README.en_US.md
Typically used to monitor the responsiveness of DNS servers, helping operations teams quickly locate network issues.
There is no need to enable this plugin on every virtual machine. It is recommended to enable it on a single dedicated or shared virtual machine.
This configuration enables or defines the following capabilities:
Use the local DNS server to check domain resolution quality.
Use external DNS servers to check domain resolution quality.
Perform DNS queries with different record types.
Set a 5-second timeout for each query.
Add custom labels, which can be used to filter data and deliver more precise alert notifications.
Add the domains you want to query in the domains field — usually your company's business system domains or third-party dependencies.
The configuration file is conf/input.dns_query/dns_query.toml.
[[instances]]
auto_detect_local_dns_server = false # Whether to auto-detect the local DNS server. When set to true, the plugin reads the locally configured DNS servers from /etc/resolv.conf
servers = ["114.114.114.114"] # List of DNS servers to query
network = "udp" # Protocol used for queries, udp or tcp
domains = ["flashcat.cloud"] # List of domains to query
record_type="NS" # DNS record type to query
port = 53 # DNS server port
timeout = 2 # DNS query timeout in seconds
expect_query_ips = { "domain" = ["IP1", "IP2", ...] } # Expected IP address configuration for domain hijacking detection
[root@aliyun input.dns_query]# cat dns_query.toml
# # collect interval
# interval = 15
[[instances]]
# # append some labels for series
labels = { cloud="huaweicloud", region="huabei-beijing-4",azone="az1", product="n9e" }
# # interval = global.interval * interval_times
# interval_times = 1
# #
auto_detect_local_dns_server = true
### A record
## servers to query
servers = ["223.5.5.5","114.114.114.114","119.29.29.29"]
## Network is the network protocol name.
# network = "udp"
## Domains or subdomains to query.
domains = ["www.huaweicloud.com", "www.baidu.com", "www.tapd.cn"]
## Query record type.
## Possible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV.
record_type = "A"
## Dns server port.
# port = 53
## Query timeout in seconds.
timeout = 5
### CNAME record
[[instances]]
# # append some labels for series
labels = { cloud="huaweicloud", region="huabei-beijing-4",azone="az1", product="n9e" }
# # interval = global.interval * interval_times
# interval_times = 1
# #
auto_detect_local_dns_server = false
## servers to query
servers = ["223.5.5.5","114.114.114.114","119.29.29.29"]
## Network is the network protocol name.
# network = "udp"
## Domains or subdomains to query.
domains = ["www.huaweicloud.com", "www.baidu.com", "www.tapd.cn"]
## Query record type.
## Possible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV.
record_type = "CNAME"
## Dns server port.
# port = 53
## Query timeout in seconds.
timeout = 5
### NS record
[[instances]]
# # append some labels for series
labels = { cloud="huaweicloud", region="huabei-beijing-4",azone="az1", product="n9e" }
# # interval = global.interval * interval_times
# interval_times = 1
# #
auto_detect_local_dns_server = false
## servers to query
servers = ["223.5.5.5","114.114.114.114","119.29.29.29"]
## Network is the network protocol name.
# network = "udp"
## Domains or subdomains to query.
domains = ["www.huaweicloud.com", "www.baidu.com", "www.tapd.cn"]
## Query record type.
## Possible values: A, AAAA, CNAME, MX, NS, PTR, TXT, SOA, SPF, SRV.
record_type = "NS"
## Dns server port.
# port = 53
## Query timeout in seconds.
timeout = 5
./categraf --test --inputs dns_query
....... A records work the same way and are omitted here
20:51:34 dns_query_rcode_value agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.tapd.cn product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 0
20:51:34 dns_query_result_code agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.tapd.cn product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 0
20:51:34 dns_query_query_time_ms agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.tapd.cn product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 33.500371
20:51:34 dns_query_rcode_value agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.baidu.com product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 0
20:51:34 dns_query_result_code agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.baidu.com product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 0
20:51:34 dns_query_query_time_ms agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.baidu.com product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 34.328242
20:51:34 dns_query_rcode_value agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.huaweicloud.com product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 0
20:51:34 dns_query_result_code agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.huaweicloud.com product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29 0
20:51:34 dns_query_query_time_ms agent_hostname=aliyun.tjf.n9e.001 azone=az1 cloud=huaweicloud domain=www.huaweicloud.com product=n9e record_type=CNAME region=huabei-beijing-4 server=119.29.29.29
.....
Restart the categraf service to apply the changes
systemctl daemon-reload && systemctl restart categraf && systemctl status categraf
Check the startup logs for errors
journalctl -f -n 500 -u categraf | grep "E\!" | grep "W\!"
After waiting 1-2 minutes, the data will show up in the charts, as shown below:
dns_query_status_change{agent_hostname="localhost",domain="baidu.com",record_type="A",server="114.114.114.114"} 1
dns_query_status_change_detail{agent_hostname="localhost",diff="182.61.201.211",domain="baidu.com",ips="182.61.201.211,182.61.244.181",record_type="A",server="114.114.114.114"} 1
Personal experience, for reference only. Typical DNS resolution latency thresholds:
Over 2000 ms: P2 level — send alerts via the WeCom app; if it recovers within 3 minutes, send a recovery notification.
Over 5000 ms: P1 level — trigger voice-call alerts plus WeCom app alerts; if it recovers within 3 minutes, send a recovery notification.
Why design it this way?
When DNS monitoring is in play, company business is usually spread across the country, and different regions can run into all kinds of DNS problems (such as DNS hijacking or regional DNS server failures), so these issues need to be treated with high severity.
The 3-minute window between the alert and the recovery notification is meant to filter out transient issues, while still leaving enough handling time for the SLA (99.99%).