mirror of
https://github.com/coredns/coredns.git
synced 2026-01-07 17:31:23 -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:
@@ -34,9 +34,14 @@ dnssec [ZONES... ] {
|
||||
will be signed with all keys. Generating a key can be done with `dnssec-keygen`: `dnssec-keygen -a
|
||||
ECDSAP256SHA256 <zonename>`. A key created for zone *A* can be safely used for zone *B*.
|
||||
|
||||
|
||||
* `cache_capacity` indicates the capacity of the LRU cache. The dnssec middleware uses LRU cache to manage
|
||||
objects and the default capacity is 10000.
|
||||
|
||||
## Metrics
|
||||
|
||||
If monitoring is enabled (via the *prometheus* directive) then the following metrics are exported:
|
||||
|
||||
* coredns_dnssec_size_guage{type} - total elements in the cache, type is "signature".
|
||||
* coredns_dnssec_capacity_guage{type} - total capacity of the cache, type is "signature".
|
||||
|
||||
## Examples
|
||||
|
||||
@@ -40,24 +40,26 @@ func (d Dnssec) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
||||
}
|
||||
|
||||
var (
|
||||
cacheHitCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
cacheSize = prometheus.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "hit_count_total",
|
||||
Help: "Counter of signatures 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 signatures that were not found in the cache.",
|
||||
}, []string{"zone"})
|
||||
Name: "capacity_gauge",
|
||||
Help: "Gauge of cache's capacity.",
|
||||
}, []string{"type"})
|
||||
)
|
||||
|
||||
func (d Dnssec) Name() string { return "dnssec" }
|
||||
|
||||
const subsystem = "dnssec"
|
||||
|
||||
func init() {
|
||||
prometheus.MustRegister(cacheHitCount)
|
||||
prometheus.MustRegister(cacheMissCount)
|
||||
prometheus.MustRegister(cacheSize)
|
||||
prometheus.MustRegister(cacheCapacity)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,8 @@ func (d *ResponseWriter) WriteMsg(res *dns.Msg) error {
|
||||
|
||||
if state.Do() {
|
||||
res = d.d.Sign(state, zone, time.Now().UTC())
|
||||
|
||||
cacheSize.WithLabelValues("signature").Set(float64(d.d.cache.Len()))
|
||||
}
|
||||
state.SizeAndDo(res)
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@ func setup(c *caddy.Controller) error {
|
||||
return New(zones, keys, next, cache)
|
||||
})
|
||||
|
||||
// Export the capacity for the metrics. This only happens once, because this is a re-load change only.
|
||||
cacheCapacity.WithLabelValues("signature").Set(float64(capacity))
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user