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, fail_on_match: bool = False, invert: bool = False) 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(protocol: str, server: urllib.parse.SplitResult, ip: IPv4Address | IPv6Address, port: int, query: Message, timeout: float) tuple[Message | None, str] ¶
Perform a DNS query with the specified server and protocol.
- get_dns_response_doh(query: Message, ip: str, port: int, timeout: float, server: urllib.parse.SplitResult, verify: str | bool) Message | None ¶
Perform a DNS query with the doh protocol and catch protocol specific exceptions.
- get_dns_response_doq(query: Message, ip: str, port: int, timeout: float, server: urllib.parse.SplitResult, verify: str | bool) Message | None ¶
Perform a DNS query with the doh protocol and catch protocol specific exceptions.
- get_dns_response_dot(query: Message, ip: str, port: int, timeout: float, server: urllib.parse.SplitResult, verify: str | bool) Message | None ¶
Perform a DNS query with the dot protocol and catch protocol specific exceptions.
- get_dns_response_tcp(query: Message, ip: str, port: int, timeout: float) Message | None ¶
Perform a DNS query with the tcp protocol.
- get_dns_response_udp(query: Message, ip: str, port: int, timeout: float) Message | None ¶
Perform a DNS query with the udp protocol.
- get_dns_response_udptcp(query: Message, ip: str, port: int, timeout: float) tuple[Message | None, str] ¶
Perform a DNS query with the udptcp protocol (with fallback to TCP).
- handle_response(response: Message, transport: str, 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.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.