mirror of
https://github.com/coredns/coredns.git
synced 2025-11-29 15:14:02 -05:00
introduce metric naming test (#3789)
* introduce metric naming test Signed-off-by: zounengren <zounengren@cmss.chinamobile.com> * Update metrics.go Signed-off-by: zounengren <zounengren@cmss.chinamobile.com>
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// autoPathCount is counter of successfully autopath-ed queries.
|
||||
autoPathCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "autopath",
|
||||
|
||||
45
plugin/cache/handler.go
vendored
45
plugin/cache/handler.go
vendored
@@ -10,7 +10,6 @@ import (
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// ServeDNS implements the plugin.Handler interface.
|
||||
@@ -128,47 +127,3 @@ func (c *Cache) exists(state request.Request) *item {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "size",
|
||||
Help: "The number of elements in the cache.",
|
||||
}, []string{"server", "type"})
|
||||
|
||||
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "hits_total",
|
||||
Help: "The count of cache hits.",
|
||||
}, []string{"server", "type"})
|
||||
|
||||
cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "misses_total",
|
||||
Help: "The count of cache misses.",
|
||||
}, []string{"server"})
|
||||
|
||||
cachePrefetches = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "prefetch_total",
|
||||
Help: "The number of time the cache has prefetched a cached item.",
|
||||
}, []string{"server"})
|
||||
|
||||
cacheDrops = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "drops_total",
|
||||
Help: "The number responses that are not cached, because the reply is malformed.",
|
||||
}, []string{"server"})
|
||||
|
||||
servedStale = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "served_stale_total",
|
||||
Help: "The number of requests served from stale cache entries.",
|
||||
}, []string{"server"})
|
||||
)
|
||||
|
||||
52
plugin/cache/metrics.go
vendored
Normal file
52
plugin/cache/metrics.go
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
// cacheSize is total elements in the cache by cache type.
|
||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "size",
|
||||
Help: "The number of elements in the cache.",
|
||||
}, []string{"server", "type"})
|
||||
// cacheHits is counter of cache hits by cache type.
|
||||
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "hits_total",
|
||||
Help: "The count of cache hits.",
|
||||
}, []string{"server", "type"})
|
||||
// cacheMisses is the counter of cache misses.
|
||||
cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "misses_total",
|
||||
Help: "The count of cache misses.",
|
||||
}, []string{"server"})
|
||||
// cachePrefetches is the number of time the cache has prefetched a cached item.
|
||||
cachePrefetches = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "prefetch_total",
|
||||
Help: "The number of time the cache has prefetched a cached item.",
|
||||
}, []string{"server"})
|
||||
// cacheDrops is the number responses that are not cached, because the reply is malformed.
|
||||
cacheDrops = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "drops_total",
|
||||
Help: "The number responses that are not cached, because the reply is malformed.",
|
||||
}, []string{"server"})
|
||||
// servedStale is the number of requests served from stale cache entries.
|
||||
servedStale = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "cache",
|
||||
Name: "served_stale_total",
|
||||
Help: "The number of requests served from stale cache entries.",
|
||||
}, []string{"server"})
|
||||
)
|
||||
@@ -53,7 +53,7 @@ used (See [bugs](#bugs)).
|
||||
|
||||
If monitoring is enabled (via the *prometheus* plugin) then the following metrics are exported:
|
||||
|
||||
* `coredns_dnssec_cache_size{server, type}` - total elements in the cache, type is "signature".
|
||||
* `coredns_dnssec_cache_entries{server, type}` - total elements in the cache, type is "signature".
|
||||
* `coredns_dnssec_cache_hits_total{server}` - Counter of cache hits.
|
||||
* `coredns_dnssec_cache_misses_total{server}` - Counter of cache misses.
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ import (
|
||||
"github.com/coredns/coredns/request"
|
||||
|
||||
"github.com/miekg/dns"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// ServeDNS implements the plugin.Handler interface.
|
||||
@@ -47,28 +46,5 @@ func (d Dnssec) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
return plugin.NextOrFailure(d.Name(), d.Next, ctx, w, r)
|
||||
}
|
||||
|
||||
var (
|
||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnssec",
|
||||
Name: "cache_size",
|
||||
Help: "The number of elements in the dnssec cache.",
|
||||
}, []string{"server", "type"})
|
||||
|
||||
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnssec",
|
||||
Name: "cache_hits_total",
|
||||
Help: "The count of cache hits.",
|
||||
}, []string{"server"})
|
||||
|
||||
cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnssec",
|
||||
Name: "cache_misses_total",
|
||||
Help: "The count of cache misses.",
|
||||
}, []string{"server"})
|
||||
)
|
||||
|
||||
// Name implements the Handler interface.
|
||||
func (d Dnssec) Name() string { return "dnssec" }
|
||||
|
||||
31
plugin/dnssec/metrics.go
Normal file
31
plugin/dnssec/metrics.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package dnssec
|
||||
|
||||
import (
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
// cacheSize is the number of elements in the dnssec cache.
|
||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnssec",
|
||||
Name: "cache_entries",
|
||||
Help: "The number of elements in the dnssec cache.",
|
||||
}, []string{"server", "type"})
|
||||
// cacheHits is the count of cache hits.
|
||||
cacheHits = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnssec",
|
||||
Name: "cache_hits_total",
|
||||
Help: "The count of cache hits.",
|
||||
}, []string{"server"})
|
||||
// cacheMisses is the count of cache misses.
|
||||
cacheMisses = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "dnssec",
|
||||
Name: "cache_misses_total",
|
||||
Help: "The count of cache misses.",
|
||||
}, []string{"server"})
|
||||
)
|
||||
@@ -76,7 +76,7 @@ hosts [FILE [ZONES...]] {
|
||||
|
||||
If monitoring is enabled (via the *prometheus* plugin) then the following metrics are exported:
|
||||
|
||||
- `coredns_hosts_entries_count{}` - The combined number of entries in hosts and Corefile.
|
||||
- `coredns_hosts_entries{}` - The combined number of entries in hosts and Corefile.
|
||||
- `coredns_hosts_reload_timestamp_seconds{}` - The timestamp of the last reload of hosts file.
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -17,8 +17,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
// parseIP calls discards any v6 zone info, before calling net.ParseIP.
|
||||
@@ -256,19 +254,3 @@ func (h *Hostsfile) LookupStaticAddr(addr string) []string {
|
||||
copy(hostsCp[len(hosts1):], hosts2)
|
||||
return hostsCp
|
||||
}
|
||||
|
||||
var (
|
||||
hostsEntries = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "hosts",
|
||||
Name: "entries_count",
|
||||
Help: "The combined number of entries in hosts and Corefile.",
|
||||
}, []string{})
|
||||
|
||||
hostsReloadTime = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "hosts",
|
||||
Name: "reload_timestamp_seconds",
|
||||
Help: "The timestamp of the last reload of hosts file.",
|
||||
})
|
||||
)
|
||||
|
||||
24
plugin/hosts/metrics.go
Normal file
24
plugin/hosts/metrics.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package hosts
|
||||
|
||||
import (
|
||||
"github.com/coredns/coredns/plugin"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
var (
|
||||
// hostsEntries is the combined number of entries in hosts and Corefile.
|
||||
hostsEntries = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "hosts",
|
||||
Name: "entries",
|
||||
Help: "The combined number of entries in hosts and Corefile.",
|
||||
}, []string{})
|
||||
// hostsReloadTime is the timestamp of the last reload of hosts file.
|
||||
hostsReloadTime = prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "hosts",
|
||||
Name: "reload_timestamp_seconds",
|
||||
Help: "The timestamp of the last reload of hosts file.",
|
||||
})
|
||||
)
|
||||
@@ -8,13 +8,14 @@ import (
|
||||
|
||||
// Metrics for the reload plugin
|
||||
var (
|
||||
FailedCount = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
// failedCount is the counter of the number of failed reload attempts.
|
||||
failedCount = prometheus.NewCounter(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "reload",
|
||||
Name: "failed_total",
|
||||
Help: "Counter of the number of failed reload attempts.",
|
||||
})
|
||||
|
||||
// reloadInfo is record the hash value during reload.
|
||||
reloadInfo = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "reload",
|
||||
|
||||
@@ -107,7 +107,7 @@ func hook(event caddy.EventName, info interface{}) error {
|
||||
reloadInfo.WithLabelValues("md5", hex.EncodeToString(md5sum[:])).Set(1)
|
||||
if err != nil {
|
||||
log.Errorf("Corefile changed but reload failed: %s", err)
|
||||
FailedCount.Add(1)
|
||||
failedCount.Add(1)
|
||||
continue
|
||||
}
|
||||
// we are done, if the plugin was not set used, then it is not.
|
||||
|
||||
@@ -71,7 +71,7 @@ func setup(c *caddy.Controller) error {
|
||||
once.Do(func() {
|
||||
caddy.RegisterEventHook("reload", hook)
|
||||
c.OnRestart(func() error {
|
||||
metrics.MustRegister(c, reloadInfo, FailedCount)
|
||||
metrics.MustRegister(c, reloadInfo, failedCount)
|
||||
return nil
|
||||
})
|
||||
})
|
||||
|
||||
@@ -9,18 +9,21 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// templateMatchesCount is the counter of template regex matches.
|
||||
templateMatchesCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "template",
|
||||
Name: "matches_total",
|
||||
Help: "Counter of template regex matches.",
|
||||
}, []string{"server", "zone", "class", "type"})
|
||||
// templateFailureCount is the counter of go template failures.
|
||||
templateFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "template",
|
||||
Name: "template_failures_total",
|
||||
Help: "Counter of go template failures.",
|
||||
}, []string{"server", "zone", "class", "type", "section", "template"})
|
||||
// templateRRFailureCount is the counter of mis-templated RRs.
|
||||
templateRRFailureCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: plugin.Namespace,
|
||||
Subsystem: "template",
|
||||
|
||||
Reference in New Issue
Block a user