Compare commits

..

No commits in common. "9382391c304384e06b6cd29f393361092077914b" and "f747d71cc0ce0f9c8100cdc3cc0a88d53f420ba6" have entirely different histories.

2 changed files with 38 additions and 34 deletions

View file

@ -159,7 +159,9 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
"servers.bind.",
}
for _, q := range questions {
responses := make([]dns.RR, len(questions))
for i, q := range questions {
msg := &dns.Msg{
MsgHdr: dns.MsgHdr{
Id: dns.Id(),
@ -175,43 +177,45 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
return err
}
for _, a := range in.Answer {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
switch txt.Hdr.Name {
case "servers.bind.":
for _, str := range txt.Txt {
arr := strings.Fields(str)
if got, want := len(arr), 3; got != want {
return fmt.Errorf("stats DNS record servers.bind.: unexpeced number of argument in record: got %d, want %d", got, want)
}
queries, err := strconv.ParseFloat(arr[1], 64)
if err != nil {
return err
}
failedQueries, err := strconv.ParseFloat(arr[2], 64)
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(serversMetrics["queries"], prometheus.GaugeValue, queries, arr[0])
ch <- prometheus.MustNewConstMetric(serversMetrics["queries_failed"], prometheus.GaugeValue, failedQueries, arr[0])
responses[i] = in.Answer[0]
}
for _, a := range responses {
txt, ok := a.(*dns.TXT)
if !ok {
continue
}
switch txt.Hdr.Name {
case "servers.bind.":
for _, str := range txt.Txt {
arr := strings.Fields(str)
if got, want := len(arr), 3; got != want {
return fmt.Errorf("stats DNS record servers.bind.: unexpeced number of argument in record: got %d, want %d", got, want)
}
default:
g, ok := floatMetrics[txt.Hdr.Name]
if !ok {
continue // ignore unexpected answer from dnsmasq
}
if got, want := len(txt.Txt), 1; got != want {
return fmt.Errorf("stats DNS record %q: unexpected number of replies: got %d, want %d", txt.Hdr.Name, got, want)
}
f, err := strconv.ParseFloat(txt.Txt[0], 64)
queries, err := strconv.ParseFloat(arr[1], 64)
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(g, prometheus.GaugeValue, f)
failedQueries, err := strconv.ParseFloat(arr[2], 64)
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(serversMetrics["queries"], prometheus.GaugeValue, queries, arr[0])
ch <- prometheus.MustNewConstMetric(serversMetrics["queries_failed"], prometheus.GaugeValue, failedQueries, arr[0])
}
default:
g, ok := floatMetrics[txt.Hdr.Name]
if !ok {
continue // ignore unexpected answer from dnsmasq
}
if got, want := len(txt.Txt), 1; got != want {
return fmt.Errorf("stats DNS record %q: unexpected number of replies: got %d, want %d", txt.Hdr.Name, got, want)
}
f, err := strconv.ParseFloat(txt.Txt[0], 64)
if err != nil {
return err
}
ch <- prometheus.MustNewConstMetric(g, prometheus.GaugeValue, f)
}
}
return nil

View file

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