dns_exporter.collector¶
dns_exporter.collector contains the DNSCollector class used by the DNSExporter during scrapes.
- class dns_exporter.collector.DNSCollector(config: Config, query: QueryMessage, labels: dict[str, str])¶
Custom collector class which does DNS lookups and returns metrics.
- check_regexes(validators: RRValidator, validator: str, rrs: str, section: str) None¶
Loop over response RRs and check for regex matches.
- collect() Iterator[CounterMetricFamily | GaugeMetricFamily]¶
Do DNS lookup and yield metrics.
- collect_dns() Iterator[CounterMetricFamily | GaugeMetricFamily]¶
Collect and yield DNS metrics.
- collect_up() Iterator[GaugeMetricFamily]¶
Yield the up metric.
- describe() Iterator[CounterMetricFamily | GaugeMetricFamily]¶
Describe the metrics that are to be returned by this collector.
- get_dns_response(*, retry: bool = False) DNSResponse¶
Perform a DNS query with the configured server and protocol.
- get_dns_response_doh(*, ip: str, port: int, http_version: HTTPVersion = HTTPVersion.HTTP_2, server: SplitResult, verify: str | SSLContext | bool) DNSResponse¶
Perform a DNS query with the doh protocol (tcp+http1/2), catch protocol specific exceptions.
- get_dns_response_doh3(*, ip: str, port: int, server: SplitResult, verify: str | bool) DNSResponse¶
Perform a DNS query with the doh3 protocol.
- get_dns_response_doq(*, ip: str, port: int, server: SplitResult, verify: str | bool) DNSResponse¶
Perform a DNS query with the doq protocol and catch protocol specific exceptions.
- get_dns_response_dot(*, ip: str, port: int, server: SplitResult, verify: str | bool) DNSResponse¶
Perform a DNS query with the dot protocol and catch protocol specific exceptions.
- get_dns_response_tcp(*, ip: str, port: int) DNSResponse¶
Perform a DNS query with the tcp protocol.
- get_dns_response_udp(*, ip: str, port: int) DNSResponse¶
Perform a DNS query with the udp protocol.
- get_dns_response_udptcp(*, ip: str, port: int) DNSResponse¶
Perform a DNS query with the udptcp protocol (with fallback to TCP).
- handle_response(*, response: Message, transport: str, connection_reused: bool, qtime: float) Iterator[CounterMetricFamily | GaugeMetricFamily]¶
Do response processing and yield metrics.
- handle_response_options(response: Message) None¶
Handle response edns.
- static increase_failure_reason_metric(failure_reason: str, labels: dict[str, str]) None¶
This method is used to maintain failure metrics.
If an empty string is passed as failure_reason (meaning success) the failure counters will not be incremented.
- validate_response(response: Message) None¶
Validate the DNS response using the validation config in the config.
- validate_response_flags(response: Message) None¶
Validate response flags.
- validate_response_rcode(response: Message) None¶
Validate response RCODE.
- validate_response_rrs(response: Message) None¶
Validate response RRs.
- yield_ttl_metrics(response: Message) Iterator[GaugeMetricFamily]¶
Register TTL of response RRs and yield ttl metric.
- class dns_exporter.collector.DNSResponse(message: Message | None, transport: str, socket_reused: bool)¶
Class to hold the result of a lookup.
- class dns_exporter.collector.FailCollector(failure_reason: str, labels: dict[str, str])¶
Custom collector class used to handle pre-DNSCollector failures, like configuration issues.
- collect_dns() Iterator[CounterMetricFamily | GaugeMetricFamily]¶
Do not collect anything, just return the error message.