Skip to content

Commit

Permalink
[dns] Add serial number metric for dns soa queries
Browse files Browse the repository at this point in the history
Signed-off-by: Ask Bjørn Hansen <[email protected]>
  • Loading branch information
abh committed Jun 12, 2018
1 parent 91e917e commit 112ccf9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ modules:
validate_additional_rrs:
fail_if_matches_regexp:
- ".*127.0.0.1"
dns_soa:
prober: dns
dns:
query_name: "prometheus.io"
query_type: "SOA"
dns_tcp_example:
prober: dns
dns:
Expand Down
34 changes: 25 additions & 9 deletions prober/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
registry.MustRegister(probeDNSAuthorityRRSGauge)
registry.MustRegister(probeDNSAdditionalRRSGauge)

qt := dns.TypeANY
if module.DNS.QueryType != "" {
var ok bool
qt, ok = dns.StringToType[module.DNS.QueryType]
if !ok {
level.Error(logger).Log("msg", "Invalid query type", "Type seen", module.DNS.QueryType, "Existing types", dns.TypeToString)
return false
}
}
var probeDNSSOAGauge prometheus.Gauge

var ip *net.IPAddr
if module.DNS.TransportProtocol == "" {
module.DNS.TransportProtocol = "udp"
Expand Down Expand Up @@ -154,15 +165,6 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
}
}

qt := dns.TypeANY
if module.DNS.QueryType != "" {
var ok bool
qt, ok = dns.StringToType[module.DNS.QueryType]
if !ok {
level.Error(logger).Log("msg", "Invalid query type", "Type seen", module.DNS.QueryType, "Existing types", dns.TypeToString)
return false
}
}
msg := new(dns.Msg)
msg.SetQuestion(dns.Fqdn(module.DNS.QueryName), qt)

Expand All @@ -180,6 +182,20 @@ func ProbeDNS(ctx context.Context, target string, module config.Module, registry
probeDNSAuthorityRRSGauge.Set(float64(len(response.Ns)))
probeDNSAdditionalRRSGauge.Set(float64(len(response.Extra)))

if qt == dns.TypeSOA {
probeDNSSOAGauge = prometheus.NewGauge(prometheus.GaugeOpts{
Name: "probe_dns_serial",
Help: "Returns the serial number of the zone",
})
registry.MustRegister(probeDNSSOAGauge)

for _, a := range response.Answer {
if soa, ok := a.(*dns.SOA); ok {
probeDNSSOAGauge.Set(float64(soa.Serial))
}
}
}

if !validRcode(response.Rcode, module.DNS.ValidRcodes, logger) {
return false
}
Expand Down

0 comments on commit 112ccf9

Please sign in to comment.