Skip to content

Commit 4051d8a

Browse files
committed
Statistics on the time taken for dns queries
1 parent 19e8a6d commit 4051d8a

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

daze.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,17 @@ var Conf = struct {
6565
// Expv is a simple wrapper around the expvars package.
6666
var Expv = struct {
6767
RouterCacheHits *expvar.Int
68-
RouterCacheMiss *expvar.Int
68+
RouterCacheCall *expvar.Int
6969
RouterCacheRate expvar.Func
7070
}{
7171
RouterCacheHits: expvar.NewInt("RouterCache.Hits"),
72-
RouterCacheMiss: expvar.NewInt("RouterCache.Miss"),
72+
RouterCacheCall: expvar.NewInt("RouterCache.Call"),
7373
RouterCacheRate: func() expvar.Func {
7474
f := expvar.Func(func() any {
7575
hits := expvar.Get("RouterCache.Hits").(*expvar.Int).Value()
76-
miss := expvar.Get("RouterCache.Miss").(*expvar.Int).Value()
77-
alls := hits + miss
78-
if alls == 0 {
79-
return 0
80-
}
81-
return float64(hits) / float64(alls)
76+
call := expvar.Get("RouterCache.Call").(*expvar.Int).Value()
77+
doa.Doa(hits <= call)
78+
return float64(hits) / float64(max(1, call))
8279
})
8380
expvar.Publish("RouterCache.Rate", f)
8481
return f
@@ -822,12 +819,12 @@ type RouterCache struct {
822819

823820
// Road implements daze.Router.
824821
func (r *RouterCache) Road(ctx *Context, host string) Road {
822+
Expv.RouterCacheCall.Add(1)
825823
a, b := r.Lru.GetExists(host)
826824
if b {
827825
Expv.RouterCacheHits.Add(1)
828826
return a
829827
}
830-
Expv.RouterCacheMiss.Add(1)
831828
c := r.Raw.Road(ctx, host)
832829
r.Lru.Set(host, c)
833830
return c

0 commit comments

Comments
 (0)