Skip to content

Commit

Permalink
metrics: Use full address for "to" metric label
Browse files Browse the repository at this point in the history
  • Loading branch information
leiless committed Apr 4, 2020
1 parent 9d7492c commit 0844db6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 3 additions & 3 deletions dnsredir.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ func (r *Dnsredir) ServeDNS(ctx context.Context, w dns.ResponseWriter, req *dns.
}
_ = w.WriteMsg(reply)

RequestCount.WithLabelValues(server, host.addr).Inc()
RequestDuration.WithLabelValues(server, host.addr).Observe(float64(time.Since(start).Milliseconds()))
RequestDuration.WithLabelValues(server, host.Name()).Observe(float64(time.Since(start).Milliseconds()))
RequestCount.WithLabelValues(server, host.Name()).Inc()

rc, ok := dns.RcodeToString[reply.Rcode]
if !ok {
rc = strconv.Itoa(reply.Rcode)
}
RcodeCount.WithLabelValues(server, host.addr, rc).Inc()
RcodeCount.WithLabelValues(server, host.Name(), rc).Inc()
return 0, nil
}

Expand Down
8 changes: 6 additions & 2 deletions healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ type UpstreamHost struct {
transport *Transport
}

func (uh *UpstreamHost)Name() string {
return uh.proto + "://" + uh.addr
}

// Taken from coredns/plugin/forward/connect.go
// see: https://en.wikipedia.org/wiki/Moving_average#Cumulative_moving_average
//
Expand Down Expand Up @@ -288,7 +292,7 @@ func (uh *UpstreamHost) Exchange(ctx context.Context, state request.Request) (*d
// basically anything else constitutes a healthy upstream.
func (uh *UpstreamHost) Check() error {
if err, rtt := uh.send(); err != nil {
HealthCheckFailureCount.WithLabelValues(uh.addr).Inc()
HealthCheckFailureCount.WithLabelValues(uh.Name()).Inc()
atomic.AddInt32(&uh.fails, 1)
log.Warningf("hc: DNS @%v +%v failed rtt: %v err: %v", uh.addr, uh.proto, rtt, err)
return err
Expand Down Expand Up @@ -339,7 +343,7 @@ func (uh *UpstreamHost) Down() bool {
down := uh.downFunc(uh)
if down {
log.Debugf("%v marked as down...", uh.addr)
HealthCheckAllDownCount.WithLabelValues(uh.addr).Inc()
HealthCheckAllDownCount.WithLabelValues(uh.Name()).Inc()
}
return down
}
Expand Down

0 comments on commit 0844db6

Please sign in to comment.