Add more metrics (#176)
This commit is contained in:
parent
2fe42067fa
commit
ef1a8604d1
5 changed files with 52 additions and 16 deletions
|
@ -11,8 +11,8 @@ import (
|
|||
|
||||
func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
|
||||
state := middleware.State{W: w, Req: r}
|
||||
qname := state.Name()
|
||||
net := state.Proto()
|
||||
|
||||
qname := state.QName()
|
||||
zone := middleware.Zones(m.ZoneNames).Matches(qname)
|
||||
if zone == "" {
|
||||
zone = "."
|
||||
|
@ -22,21 +22,33 @@ func (m Metrics) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg)
|
|||
rw := middleware.NewResponseRecorder(w)
|
||||
status, err := m.Next.ServeDNS(ctx, rw, r)
|
||||
|
||||
Report(zone, net, rw.Rcode(), rw.Size(), rw.Start())
|
||||
Report(state, zone, rw.Rcode(), rw.Size(), rw.Start())
|
||||
|
||||
return status, err
|
||||
}
|
||||
|
||||
// Report is a plain reporting function that the server can use for REFUSED and other
|
||||
// queries that are turned down because they don't match any middleware.
|
||||
func Report(zone, net, rcode string, size int, start time.Time) {
|
||||
func Report(state middleware.State, zone, rcode string, size int, start time.Time) {
|
||||
if requestCount == nil {
|
||||
// no metrics are enabled
|
||||
return
|
||||
}
|
||||
|
||||
requestCount.WithLabelValues(zone, net).Inc()
|
||||
// Proto and Family
|
||||
net := state.Proto()
|
||||
fam := "1"
|
||||
if state.Family() == 2 {
|
||||
fam = "2"
|
||||
}
|
||||
|
||||
requestCount.WithLabelValues(zone, net, fam).Inc()
|
||||
requestDuration.WithLabelValues(zone).Observe(float64(time.Since(start) / time.Second))
|
||||
requestSize.WithLabelValues(zone).Observe(float64(state.Size()))
|
||||
if state.Do() {
|
||||
requestDo.WithLabelValues(zone).Inc()
|
||||
}
|
||||
|
||||
responseSize.WithLabelValues(zone).Observe(float64(size))
|
||||
responseRcode.WithLabelValues(zone, rcode).Inc()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue