mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 18:53:43 -04:00
middleware/cache: Add metrics (#132)
Add prometheus metrics to the cache handler. This just used prometheus, if the metrics middleware does not setup the handler, there is nobody reading these metrics, but they are still reported. Seems the simplest solution while keeping the whole middleware separation in tact.
This commit is contained in:
28
middleware/cache/handler.go
vendored
28
middleware/cache/handler.go
vendored
@@ -4,6 +4,7 @@ import (
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
@@ -24,8 +25,12 @@ func (c Cache) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (
|
||||
resp := i.toMsg(r)
|
||||
state.SizeAndDo(resp)
|
||||
w.WriteMsg(resp)
|
||||
|
||||
cacheHitCount.WithLabelValues(zone).Inc()
|
||||
return dns.RcodeSuccess, nil
|
||||
}
|
||||
cacheMissCount.WithLabelValues(zone).Inc()
|
||||
|
||||
crr := NewCachingResponseWriter(w, c.cache, c.cap)
|
||||
return c.Next.ServeDNS(ctx, crr, r)
|
||||
}
|
||||
@@ -42,3 +47,26 @@ func (c Cache) Get(qname string, qtype uint16, do bool) (*item, bool) {
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
var (
|
||||
cacheHitCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "hit_count_total",
|
||||
Help: "Counter of DNS requests that were found in the cache.",
|
||||
}, []string{"zone"})
|
||||
|
||||
cacheMissCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "miss_count_total",
|
||||
Help: "Counter of DNS requests that were not found in the cache.",
|
||||
}, []string{"zone"})
|
||||
)
|
||||
|
||||
const subsystem = "cache"
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(cacheHitCount)
|
||||
prometheus.MustRegister(cacheMissCount)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user