Skip to content

Commit 7a85ddb

Browse files
committed
new zone metrics
1 parent c8120bf commit 7a85ddb

File tree

5 files changed

+66
-11
lines changed

5 files changed

+66
-11
lines changed

bind/bind.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,10 @@ type Counter struct {
131131

132132
// Counter represents a single zone counter value.
133133
type ZoneCounter struct {
134-
Name string
135-
Serial string
134+
Name string
135+
Serial string
136+
ZoneRcode []Counter
137+
ZoneQtype []Counter
136138
}
137139

138140
// Gauge represents a single gauge value.

bind/v3/v3.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ type ZoneView struct {
6868
Zones []ZoneCounter `xml:"zones>zone"`
6969
}
7070

71+
type ZoneCounter struct {
72+
Name string `xml:"name,attr"`
73+
Rdataclass string `xml:"rdataclass,attr"`
74+
Serial string `xml:"serial"`
75+
Counters []Counters `xml:"counters"`
76+
}
77+
7178
type Counters struct {
7279
Type string `xml:"type,attr"`
7380
Counters []bind.Counter `xml:"counter"`
@@ -78,12 +85,6 @@ type Counter struct {
7885
Counter uint64 `xml:"counter"`
7986
}
8087

81-
type ZoneCounter struct {
82-
Name string `xml:"name,attr"`
83-
Rdataclass string `xml:"rdataclass,attr"`
84-
Serial string `xml:"serial"`
85-
}
86-
8788
// Client implements bind.Client and can be used to query a BIND v3 API.
8889
type Client struct {
8990
*bind.XMLClient
@@ -159,6 +160,14 @@ func (c *Client) Stats(groups ...bind.StatisticGroup) (bind.Statistics, error) {
159160
Name: zone.Name,
160161
Serial: zone.Serial,
161162
}
163+
for _, x := range zone.Counters {
164+
switch x.Type {
165+
case rcode:
166+
z.ZoneRcode = x.Counters
167+
case qtype:
168+
z.ZoneQtype = x.Counters
169+
}
170+
}
162171
v.ZoneData = append(v.ZoneData, z)
163172
}
164173
s.ZoneViews = append(s.ZoneViews, v)

bind_exporter.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import (
2929
"github.com/prometheus-community/bind_exporter/bind"
3030
"github.com/prometheus-community/bind_exporter/bind/auto"
3131
"github.com/prometheus-community/bind_exporter/bind/json"
32-
"github.com/prometheus-community/bind_exporter/bind/v2"
33-
"github.com/prometheus-community/bind_exporter/bind/v3"
32+
v2 "github.com/prometheus-community/bind_exporter/bind/v2"
33+
v3 "github.com/prometheus-community/bind_exporter/bind/v3"
3434
"github.com/prometheus/client_golang/prometheus"
3535
"github.com/prometheus/client_golang/prometheus/collectors"
3636
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -220,6 +220,16 @@ var (
220220
"Zone serial number.",
221221
[]string{"view", "zone_name"}, nil,
222222
)
223+
zoneRcode = prometheus.NewDesc(
224+
prometheus.BuildFQName(namespace, "", "zone_incoming_rcodes_total"),
225+
"Number of incoming DNS requests per zone.",
226+
[]string{"zone_name", "rcode"}, nil,
227+
)
228+
zoneQtype = prometheus.NewDesc(
229+
prometheus.BuildFQName(namespace, "", "zone_incoming_queries_total"),
230+
"Number of incoming DNS requests per zone.",
231+
[]string{"zone_name", "type"}, nil,
232+
)
223233
)
224234

225235
type collectorConstructor func(*bind.Statistics) prometheus.Collector
@@ -358,6 +368,24 @@ func (c *viewCollector) Collect(ch chan<- prometheus.Metric) {
358368
}
359369
}
360370
}
371+
for _, v := range c.stats.ZoneViews {
372+
for _, z := range v.ZoneData {
373+
for _, x := range z.ZoneRcode {
374+
ch <- prometheus.MustNewConstMetric(
375+
zoneRcode, prometheus.CounterValue, float64(x.Counter), z.Name, x.Name,
376+
)
377+
}
378+
}
379+
}
380+
for _, v := range c.stats.ZoneViews {
381+
for _, z := range v.ZoneData {
382+
for _, x := range z.ZoneQtype {
383+
ch <- prometheus.MustNewConstMetric(
384+
zoneQtype, prometheus.CounterValue, float64(x.Counter), z.Name, x.Name,
385+
)
386+
}
387+
}
388+
}
361389
}
362390

363391
type taskCollector struct {

bind_exporter_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,14 @@ var (
6969
`bind_resolver_response_errors_total{error="REFUSED",view="_bind"} 17`,
7070
`bind_resolver_response_errors_total{error="REFUSED",view="_default"} 5798`,
7171
})
72+
73+
zoneStatsV3 = []string{
74+
`bind_zone_incoming_rcodes_total{rcode="QrySuccess",zone_name="TEST_ZONE"} 163729`,
75+
`bind_zone_incoming_rcodes_total{rcode="QryNXDOMAIN",zone_name="TEST_ZONE"} 4512`,
76+
`bind_zone_incoming_queries_total{type="A",zone_name="TEST_ZONE"} 123123`,
77+
`bind_zone_incoming_queries_total{type="CNAME",zone_name="TEST_ZONE"} 14953`,
78+
}
79+
7280
taskStats = []string{
7381
`bind_tasks_running 8`,
7482
`bind_worker_threads 16`,
@@ -99,7 +107,7 @@ func TestBindExporterV3Client(t *testing.T) {
99107
server: newV3Server(),
100108
groups: []bind.StatisticGroup{bind.ServerStats, bind.ViewStats, bind.TaskStats},
101109
version: "xml.v3",
102-
include: combine([]string{`bind_up 1`}, serverStatsV3, viewStatsV3, taskStats),
110+
include: combine([]string{`bind_up 1`}, serverStatsV3, viewStatsV3, zoneStatsV3, taskStats),
103111
}.run(t)
104112
}
105113

fixtures/v3/zones

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@
77
<zone name="TEST_ZONE" rdataclass="IN">
88
<type>builtin</type>
99
<serial>123</serial>
10+
<counters type="rcode">
11+
<counter name="QryNXDOMAIN">4512</counter>
12+
<counter name="QrySuccess">163729</counter>
13+
</counters>
14+
<counters type="qtype">
15+
<counter name="A">123123</counter>
16+
<counter name="CNAME">14953</counter>
17+
</counters>
1018
</zone>
1119
</zones>
1220
</view>

0 commit comments

Comments
 (0)