Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bind/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 15 additions & 6 deletions bind/v3/v3.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Balance

case qtype:
z.ZoneQtype = x.Counters
}
}
v.ZoneData = append(v.ZoneData, z)
}
s.ZoneViews = append(s.ZoneViews, v)
Expand Down
28 changes: 28 additions & 0 deletions bind_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 9 additions & 1 deletion bind_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand Down Expand Up @@ -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)
}

Expand Down
8 changes: 8 additions & 0 deletions fixtures/v3/zones
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
<zone name="TEST_ZONE" rdataclass="IN">
<type>builtin</type>
<serial>123</serial>
<counters type="rcode">
<counter name="QryNXDOMAIN">4512</counter>
<counter name="QrySuccess">163729</counter>
</counters>
<counters type="qtype">
<counter name="A">123123</counter>
<counter name="CNAME">14953</counter>
</counters>
</zone>
</zones>
</view>
Expand Down