mirror of
https://github.com/coredns/coredns.git
synced 2025-11-08 21:16:24 -05:00
middleware/metrics: cleanup (#355)
* middleware/metrics: add more metrics middleware/cache: Add metrics for number of elements in the cache. Also export the total size. Update README to detail the new metrics. middleware/metrics Move metrics into subpackage called "vars". This breaks the import cycle and is cleaner. This allows vars.Report to be used in the the dnsserver to log refused queries. middleware/metrics: tests Add tests to the metrics framework. The metrics/test subpackage allows scraping of the local server. Do a few test scrape of the metrics that are defined in the metrics middleware. This also allows metrics integration tests to check if the caching and dnssec middleware export their metrics correctly. * update README * typos * fix tests
This commit is contained in:
26
middleware/cache/handler.go
vendored
26
middleware/cache/handler.go
vendored
@@ -30,17 +30,15 @@ func (c *Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
state.SizeAndDo(resp)
|
||||
w.WriteMsg(resp)
|
||||
|
||||
cacheHitCount.WithLabelValues(zone).Inc()
|
||||
|
||||
return dns.RcodeSuccess, nil
|
||||
}
|
||||
|
||||
cacheMissCount.WithLabelValues(zone).Inc()
|
||||
|
||||
crr := &ResponseWriter{w, c}
|
||||
return c.Next.ServeDNS(ctx, crr, r)
|
||||
}
|
||||
|
||||
func (c *Cache) Name() string { return "cache" }
|
||||
|
||||
func (c *Cache) get(qname string, qtype uint16, do bool) (*item, bool, bool) {
|
||||
k := rawKey(qname, qtype, do)
|
||||
|
||||
@@ -55,24 +53,24 @@ func (c *Cache) get(qname string, qtype uint16, do bool) (*item, bool, bool) {
|
||||
}
|
||||
|
||||
var (
|
||||
cacheHitCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "hit_count_total",
|
||||
Help: "Counter of DNS requests that were found in the cache.",
|
||||
}, []string{"zone"})
|
||||
Name: "size_guage",
|
||||
Help: "Gauge of number of elements in the cache.",
|
||||
}, []string{"type"})
|
||||
|
||||
cacheMissCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
cacheCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "miss_count_total",
|
||||
Help: "Counter of DNS requests that were not found in the cache.",
|
||||
}, []string{"zone"})
|
||||
Name: "capacity_gauge",
|
||||
Help: "Gauge of cache's capacity.",
|
||||
}, []string{"type"})
|
||||
)
|
||||
|
||||
const subsystem = "cache"
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(cacheHitCount)
|
||||
prometheus.MustRegister(cacheMissCount)
|
||||
prometheus.MustRegister(cacheSize)
|
||||
prometheus.MustRegister(cacheCapacity)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user