Update cache metrics (#4781)
Add a total cache request counter to follow Prometheus conventions[0]. Mark the existing cache miss metric as deprecated. > Similarly, with hit or miss for caches, it’s better to have one > metric for total and another for hits. [0]: https://prometheus.io/docs/instrumenting/writing_exporters/#naming Signed-off-by: SuperQ <superq@gmail.com>
This commit is contained in:
parent
88d94dc148
commit
7d542fec67
3 changed files with 13 additions and 3 deletions
3
plugin/cache/README.md
vendored
3
plugin/cache/README.md
vendored
|
@ -75,7 +75,8 @@ If monitoring is enabled (via the *prometheus* plugin) then the following metric
|
||||||
|
|
||||||
* `coredns_cache_entries{server, type}` - Total elements in the cache by cache type.
|
* `coredns_cache_entries{server, type}` - Total elements in the cache by cache type.
|
||||||
* `coredns_cache_hits_total{server, type}` - Counter of cache hits by cache type.
|
* `coredns_cache_hits_total{server, type}` - Counter of cache hits by cache type.
|
||||||
* `coredns_cache_misses_total{server}` - Counter of cache misses.
|
* `coredns_cache_misses_total{server}` - Counter of cache misses. - Deprecated, derive misses from cache hits/requests counters.
|
||||||
|
* `coredns_cache_requests_total{server}` - Counter of cache requests.
|
||||||
* `coredns_cache_prefetch_total{server}` - Counter of times the cache has prefetched a cached item.
|
* `coredns_cache_prefetch_total{server}` - Counter of times the cache has prefetched a cached item.
|
||||||
* `coredns_cache_drops_total{server}` - Counter of responses excluded from the cache due to request/response question name mismatch.
|
* `coredns_cache_drops_total{server}` - Counter of responses excluded from the cache due to request/response question name mismatch.
|
||||||
* `coredns_cache_served_stale_total{server}` - Counter of requests served from stale cache entries.
|
* `coredns_cache_served_stale_total{server}` - Counter of requests served from stale cache entries.
|
||||||
|
|
2
plugin/cache/handler.go
vendored
2
plugin/cache/handler.go
vendored
|
@ -91,6 +91,7 @@ func (c *Cache) Name() string { return "cache" }
|
||||||
|
|
||||||
func (c *Cache) get(now time.Time, state request.Request, server string) (*item, bool) {
|
func (c *Cache) get(now time.Time, state request.Request, server string) (*item, bool) {
|
||||||
k := hash(state.Name(), state.QType())
|
k := hash(state.Name(), state.QType())
|
||||||
|
cacheRequests.WithLabelValues(server).Inc()
|
||||||
|
|
||||||
if i, ok := c.ncache.Get(k); ok && i.(*item).ttl(now) > 0 {
|
if i, ok := c.ncache.Get(k); ok && i.(*item).ttl(now) > 0 {
|
||||||
cacheHits.WithLabelValues(server, Denial).Inc()
|
cacheHits.WithLabelValues(server, Denial).Inc()
|
||||||
|
@ -108,6 +109,7 @@ func (c *Cache) get(now time.Time, state request.Request, server string) (*item,
|
||||||
// getIgnoreTTL unconditionally returns an item if it exists in the cache.
|
// getIgnoreTTL unconditionally returns an item if it exists in the cache.
|
||||||
func (c *Cache) getIgnoreTTL(now time.Time, state request.Request, server string) *item {
|
func (c *Cache) getIgnoreTTL(now time.Time, state request.Request, server string) *item {
|
||||||
k := hash(state.Name(), state.QType())
|
k := hash(state.Name(), state.QType())
|
||||||
|
cacheRequests.WithLabelValues(server).Inc()
|
||||||
|
|
||||||
if i, ok := c.ncache.Get(k); ok {
|
if i, ok := c.ncache.Get(k); ok {
|
||||||
ttl := i.(*item).ttl(now)
|
ttl := i.(*item).ttl(now)
|
||||||
|
|
11
plugin/cache/metrics.go
vendored
11
plugin/cache/metrics.go
vendored
|
@ -15,6 +15,13 @@ var (
|
||||||
Name: "entries",
|
Name: "entries",
|
||||||
Help: "The number of elements in the cache.",
|
Help: "The number of elements in the cache.",
|
||||||
}, []string{"server", "type"})
|
}, []string{"server", "type"})
|
||||||
|
// cacheRequests is a counter of all requests through the cache.
|
||||||
|
cacheRequests = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
Namespace: plugin.Namespace,
|
||||||
|
Subsystem: "cache",
|
||||||
|
Name: "requests_total",
|
||||||
|
Help: "The count of cache requests.",
|
||||||
|
}, []string{"server"})
|
||||||
// cacheHits is counter of cache hits by cache type.
|
// cacheHits is counter of cache hits by cache type.
|
||||||
cacheHits = promauto.NewCounterVec(prometheus.CounterOpts{
|
cacheHits = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: plugin.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
|
@ -22,12 +29,12 @@ var (
|
||||||
Name: "hits_total",
|
Name: "hits_total",
|
||||||
Help: "The count of cache hits.",
|
Help: "The count of cache hits.",
|
||||||
}, []string{"server", "type"})
|
}, []string{"server", "type"})
|
||||||
// cacheMisses is the counter of cache misses.
|
// cacheMisses is the counter of cache misses. - Deprecated
|
||||||
cacheMisses = promauto.NewCounterVec(prometheus.CounterOpts{
|
cacheMisses = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
Namespace: plugin.Namespace,
|
Namespace: plugin.Namespace,
|
||||||
Subsystem: "cache",
|
Subsystem: "cache",
|
||||||
Name: "misses_total",
|
Name: "misses_total",
|
||||||
Help: "The count of cache misses.",
|
Help: "The count of cache misses. Deprecated, derive misses from cache hits/requests counters.",
|
||||||
}, []string{"server"})
|
}, []string{"server"})
|
||||||
// cachePrefetches is the number of time the cache has prefetched a cached item.
|
// cachePrefetches is the number of time the cache has prefetched a cached item.
|
||||||
cachePrefetches = promauto.NewCounterVec(prometheus.CounterOpts{
|
cachePrefetches = promauto.NewCounterVec(prometheus.CounterOpts{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue