From ab15238b110f6e8388d6be673188e25de293d397 Mon Sep 17 00:00:00 2001 From: maxiaoyu Date: Tue, 16 Apr 2024 20:03:25 +0800 Subject: [PATCH] update add bind view cachestats Signed-off-by: maxiaoyu --- bind/bind.go | 1 + bind/json/json.go | 10 +++++++--- bind_exporter.go | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bind/bind.go b/bind/bind.go index c2379b4..ccbf79a 100644 --- a/bind/bind.go +++ b/bind/bind.go @@ -61,6 +61,7 @@ type Server struct { type View struct { Name string Cache []Gauge + CacheStats []Counter ResolverStats []Counter ResolverQueries []Counter } diff --git a/bind/json/json.go b/bind/json/json.go index d20ecd2..36eb465 100644 --- a/bind/json/json.go +++ b/bind/json/json.go @@ -47,9 +47,10 @@ type Statistics struct { ZoneStats Counters `json:"zonestats"` Views map[string]struct { Resolver struct { - Cache Gauges `json:"cache"` - Qtypes Counters `json:"qtypes"` - Stats Counters `json:"stats"` + Cache Gauges `json:"cache"` + Qtypes Counters `json:"qtypes"` + Stats Counters `json:"stats"` + CacheStats Counters `json:"cachestats"` } `json:"resolver"` } `json:"views"` } @@ -156,6 +157,9 @@ func (c *Client) Stats(groups ...bind.StatisticGroup) (bind.Statistics, error) { for k, val := range view.Resolver.Stats { v.ResolverStats = append(v.ResolverStats, bind.Counter{Name: k, Counter: val}) } + for k, val := range view.Resolver.CacheStats { + v.CacheStats = append(v.CacheStats, bind.Counter{Name: k, Counter: val}) + } s.Views = append(s.Views, v) } } diff --git a/bind_exporter.go b/bind_exporter.go index bac37ff..0a21035 100644 --- a/bind_exporter.go +++ b/bind_exporter.go @@ -77,6 +77,11 @@ var ( "Number of RRSets in Cache database.", []string{"view", "type"}, nil, ) + resolverCacheStats = prometheus.NewDesc( + prometheus.BuildFQName(namespace, resolver, "cache_stats"), + "Number of Cache Stats in Cache database.", + []string{"view", "stat"}, nil, + ) resolverQueries = prometheus.NewDesc( prometheus.BuildFQName(namespace, resolver, "queries_total"), "Number of outgoing DNS queries.", @@ -323,6 +328,11 @@ func (c *viewCollector) Collect(ch chan<- prometheus.Metric) { resolverCache, prometheus.GaugeValue, float64(s.Gauge), v.Name, s.Name, ) } + for _, s := range v.CacheStats { + ch <- prometheus.MustNewConstMetric( + resolverCacheStats, prometheus.GaugeValue, float64(s.Counter), v.Name, s.Name, + ) + } for _, s := range v.ResolverQueries { ch <- prometheus.MustNewConstMetric( resolverQueries, prometheus.CounterValue, float64(s.Counter), v.Name, s.Name,