Compare commits

...

2 commits

Author SHA1 Message Date
Gabriel Simmer 9382391c30
Formatting 2024-04-24 08:48:45 +01:00
Gabriel Simmer 5107e16233
Better collection of DNS queries
SingleInflight is now a noop in the dns package, so we have to
implement it ourselves. I've found that dnsmasq just times out when
sending all the questions together.
2024-04-24 08:47:23 +01:00
2 changed files with 36 additions and 40 deletions

View file

@ -159,9 +159,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
"servers.bind.", "servers.bind.",
} }
responses := make([]dns.RR, len(questions)) for _, q := range questions {
for i, q := range questions {
msg := &dns.Msg{ msg := &dns.Msg{
MsgHdr: dns.MsgHdr{ MsgHdr: dns.MsgHdr{
Id: dns.Id(), Id: dns.Id(),
@ -177,10 +175,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
return err return err
} }
responses[i] = in.Answer[0] for _, a := range in.Answer {
}
for _, a := range responses {
txt, ok := a.(*dns.TXT) txt, ok := a.(*dns.TXT)
if !ok { if !ok {
continue continue
@ -218,6 +213,7 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(g, prometheus.GaugeValue, f) ch <- prometheus.MustNewConstMetric(g, prometheus.GaugeValue, f)
} }
} }
}
return nil return nil
}) })

View file

@ -23,8 +23,8 @@ import (
"github.com/google/dnsmasq_exporter/collector" "github.com/google/dnsmasq_exporter/collector"
"github.com/miekg/dns" "github.com/miekg/dns"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/client_golang/prometheus/collectors/version" "github.com/prometheus/client_golang/prometheus/collectors/version"
"github.com/prometheus/client_golang/prometheus/promhttp"
) )
var ( var (