Skip to content

Commit d132a84

Browse files
committed
Add resolver cache statistics metrics
Signed-off-by: Joel Welti <[email protected]>
1 parent 13a66ce commit d132a84

File tree

4 files changed

+28
-10
lines changed

4 files changed

+28
-10
lines changed

bind/bind.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type View struct {
6363
Cache []Gauge
6464
ResolverStats []Counter
6565
ResolverQueries []Counter
66+
CacheStats []Counter
6667
}
6768

6869
// View represents statistics for a single BIND zone view.

bind/json/json.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ type Statistics struct {
4747
ZoneStats Counters `json:"zonestats"`
4848
Views map[string]struct {
4949
Resolver struct {
50-
Cache Gauges `json:"cache"`
51-
Qtypes Counters `json:"qtypes"`
52-
Stats Counters `json:"stats"`
50+
Cache Gauges `json:"cache"`
51+
Qtypes Counters `json:"qtypes"`
52+
Stats Counters `json:"stats"`
53+
CacheStats Counters `json:"cachestats"`
5354
} `json:"resolver"`
5455
} `json:"views"`
5556
}
@@ -156,6 +157,9 @@ func (c *Client) Stats(groups ...bind.StatisticGroup) (bind.Statistics, error) {
156157
for k, val := range view.Resolver.Stats {
157158
v.ResolverStats = append(v.ResolverStats, bind.Counter{Name: k, Counter: val})
158159
}
160+
for k, val := range view.Resolver.CacheStats {
161+
v.CacheStats = append(v.CacheStats, bind.Counter{Name: k, Counter: val})
162+
}
159163
s.Views = append(s.Views, v)
160164
}
161165
}

bind/xml/xml.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ const (
3434
// ZonesPath is the HTTP path of the v3 zones resource.
3535
ZonesPath = "/xml/v3/zones"
3636

37-
nsstat = "nsstat"
38-
opcode = "opcode"
39-
qtype = "qtype"
40-
resqtype = "resqtype"
41-
resstats = "resstats"
42-
zonestat = "zonestat"
43-
rcode = "rcode"
37+
nsstat = "nsstat"
38+
opcode = "opcode"
39+
qtype = "qtype"
40+
resqtype = "resqtype"
41+
resstats = "resstats"
42+
zonestat = "zonestat"
43+
rcode = "rcode"
44+
cachestats = "cachestats"
4445
)
4546

4647
type Statistics struct {
@@ -170,6 +171,8 @@ func (c *Client) Stats(groups ...bind.StatisticGroup) (bind.Statistics, error) {
170171
v.ResolverQueries = c.Counters
171172
case resstats:
172173
v.ResolverStats = c.Counters
174+
case cachestats:
175+
v.CacheStats = c.Counters
173176
}
174177
}
175178
s.Views = append(s.Views, v)

bind_exporter.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ var (
8282
"Number of outgoing DNS queries.",
8383
[]string{"view", "type"}, nil,
8484
)
85+
cacheStats = prometheus.NewDesc(
86+
prometheus.BuildFQName(namespace, resolver, "cache_stats"),
87+
"Resolver cache statistics.",
88+
[]string{"view", "type"}, nil,
89+
)
8590
resolverQueryDuration = prometheus.NewDesc(
8691
prometheus.BuildFQName(namespace, resolver, "query_duration_seconds"),
8792
"Resolver query round-trip time in seconds.",
@@ -333,6 +338,11 @@ func (c *viewCollector) Collect(ch chan<- prometheus.Metric) {
333338
resolverQueries, prometheus.CounterValue, float64(s.Counter), v.Name, s.Name,
334339
)
335340
}
341+
for _, s := range v.CacheStats {
342+
ch <- prometheus.MustNewConstMetric(
343+
cacheStats, prometheus.CounterValue, float64(s.Counter), v.Name, s.Name,
344+
)
345+
}
336346
for _, s := range v.ResolverStats {
337347
if desc, ok := resolverMetricStats[s.Name]; ok {
338348
ch <- prometheus.MustNewConstMetric(

0 commit comments

Comments
 (0)