mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 16:24:19 -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:
@@ -6,11 +6,10 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/miekg/coredns/middleware"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
)
|
||||
|
||||
const namespace = "coredns"
|
||||
|
||||
var (
|
||||
requestCount *prometheus.CounterVec
|
||||
requestDuration *prometheus.HistogramVec
|
||||
@@ -48,18 +47,15 @@ func (m *Metrics) Start() error {
|
||||
}
|
||||
|
||||
func define(subsystem string) {
|
||||
if subsystem == "" {
|
||||
subsystem = "dns"
|
||||
}
|
||||
requestCount = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "request_count_total",
|
||||
Help: "Counter of DNS requests made per zone and protocol.",
|
||||
}, []string{"zone", "proto"})
|
||||
|
||||
requestDuration = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "request_duration_seconds",
|
||||
Buckets: append([]float64{.0001, .0005, .001, .0025}, prometheus.DefBuckets...),
|
||||
@@ -67,7 +63,7 @@ func define(subsystem string) {
|
||||
}, []string{"zone"})
|
||||
|
||||
responseSize = prometheus.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: namespace,
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "response_size_bytes",
|
||||
Help: "Size of the returns response in bytes.",
|
||||
@@ -75,12 +71,16 @@ func define(subsystem string) {
|
||||
}, []string{"zone"})
|
||||
|
||||
responseRcode = prometheus.NewCounterVec(prometheus.CounterOpts{
|
||||
Namespace: namespace,
|
||||
Namespace: middleware.Namespace,
|
||||
Subsystem: subsystem,
|
||||
Name: "response_rcode_count_total",
|
||||
Help: "Counter of response status codes.",
|
||||
}, []string{"zone", "rcode"})
|
||||
}
|
||||
|
||||
// Dropped indicates we dropped the query before any handling. It has no closing dot, so it can not be a valid zone.
|
||||
const Dropped = "dropped"
|
||||
const (
|
||||
// Dropped indicates we dropped the query before any handling. It has no closing dot, so it can not be a valid zone.
|
||||
Dropped = "dropped"
|
||||
|
||||
subsystem = "dns"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user