diff --git a/bind/bind.go b/bind/bind.go index 757bf67b..2a23435e 100644 --- a/bind/bind.go +++ b/bind/bind.go @@ -131,8 +131,10 @@ type Counter struct { // Counter represents a single zone counter value. type ZoneCounter struct { - Name string - Serial string + Name string + Serial string + ZoneRcode []Counter + ZoneQtype []Counter } // Gauge represents a single gauge value. diff --git a/bind/v3/v3.go b/bind/v3/v3.go index fdd36863..2ff3ad48 100644 --- a/bind/v3/v3.go +++ b/bind/v3/v3.go @@ -68,6 +68,13 @@ type ZoneView struct { Zones []ZoneCounter `xml:"zones>zone"` } +type ZoneCounter struct { + Name string `xml:"name,attr"` + Rdataclass string `xml:"rdataclass,attr"` + Serial string `xml:"serial"` + Counters []Counters `xml:"counters"` +} + type Counters struct { Type string `xml:"type,attr"` Counters []bind.Counter `xml:"counter"` @@ -78,12 +85,6 @@ type Counter struct { Counter uint64 `xml:"counter"` } -type ZoneCounter struct { - Name string `xml:"name,attr"` - Rdataclass string `xml:"rdataclass,attr"` - Serial string `xml:"serial"` -} - // Client implements bind.Client and can be used to query a BIND v3 API. type Client struct { *bind.XMLClient @@ -159,6 +160,14 @@ func (c *Client) Stats(groups ...bind.StatisticGroup) (bind.Statistics, error) { Name: zone.Name, Serial: zone.Serial, } + for _, x := range zone.Counters { + switch x.Type { + case rcode: + z.ZoneRcode = x.Counters + case qtype: + z.ZoneQtype = x.Counters + } + } v.ZoneData = append(v.ZoneData, z) } s.ZoneViews = append(s.ZoneViews, v) diff --git a/bind_exporter.go b/bind_exporter.go index 0756c0f0..f1ee31ab 100644 --- a/bind_exporter.go +++ b/bind_exporter.go @@ -220,6 +220,16 @@ var ( "Zone serial number.", []string{"view", "zone_name"}, nil, ) + zoneRcode = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "zone_incoming_rcodes_total"), + "Number of incoming DNS requests per zone.", + []string{"zone_name", "rcode"}, nil, + ) + zoneQtype = prometheus.NewDesc( + prometheus.BuildFQName(namespace, "", "zone_incoming_queries_total"), + "Number of incoming DNS requests per zone.", + []string{"zone_name", "type"}, nil, + ) ) type collectorConstructor func(*bind.Statistics) prometheus.Collector @@ -358,6 +368,24 @@ func (c *viewCollector) Collect(ch chan<- prometheus.Metric) { } } } + for _, v := range c.stats.ZoneViews { + for _, z := range v.ZoneData { + for _, x := range z.ZoneRcode { + ch <- prometheus.MustNewConstMetric( + zoneRcode, prometheus.CounterValue, float64(x.Counter), z.Name, x.Name, + ) + } + } + } + for _, v := range c.stats.ZoneViews { + for _, z := range v.ZoneData { + for _, x := range z.ZoneQtype { + ch <- prometheus.MustNewConstMetric( + zoneQtype, prometheus.CounterValue, float64(x.Counter), z.Name, x.Name, + ) + } + } + } } type taskCollector struct { diff --git a/bind_exporter_test.go b/bind_exporter_test.go index 9dee3c82..5f33af02 100644 --- a/bind_exporter_test.go +++ b/bind_exporter_test.go @@ -69,6 +69,14 @@ var ( `bind_resolver_response_errors_total{error="REFUSED",view="_bind"} 17`, `bind_resolver_response_errors_total{error="REFUSED",view="_default"} 5798`, }) + + zoneStatsV3 = []string{ + `bind_zone_incoming_rcodes_total{rcode="QrySuccess",zone_name="TEST_ZONE"} 163729`, + `bind_zone_incoming_rcodes_total{rcode="QryNXDOMAIN",zone_name="TEST_ZONE"} 4512`, + `bind_zone_incoming_queries_total{type="A",zone_name="TEST_ZONE"} 123123`, + `bind_zone_incoming_queries_total{type="CNAME",zone_name="TEST_ZONE"} 14953`, + } + taskStats = []string{ `bind_tasks_running 8`, `bind_worker_threads 16`, @@ -99,7 +107,7 @@ func TestBindExporterV3Client(t *testing.T) { server: newV3Server(), groups: []bind.StatisticGroup{bind.ServerStats, bind.ViewStats, bind.TaskStats}, version: "xml.v3", - include: combine([]string{`bind_up 1`}, serverStatsV3, viewStatsV3, taskStats), + include: combine([]string{`bind_up 1`}, serverStatsV3, viewStatsV3, zoneStatsV3, taskStats), }.run(t) } diff --git a/fixtures/v3/zones b/fixtures/v3/zones index b70509c9..5e81b88b 100644 --- a/fixtures/v3/zones +++ b/fixtures/v3/zones @@ -7,6 +7,14 @@ builtin 123 + + 4512 + 163729 + + + 123123 + 14953 +