diff --git a/pool/pool.go b/pool/pool.go index fa5d368b..90b2ead9 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -62,6 +62,7 @@ type clientStatus interface { overallErrorRate() uint64 resetErrorCounter() latency() time.Duration + requests() uint64 } type clientStatusMonitor struct { @@ -572,7 +573,15 @@ func (c *clientStatusMonitor) resetErrorCounter() { } func (c *clientStatusMonitor) latency() time.Duration { - return time.Duration(c.allTime.Load() / c.allRequests.Load()) + allRequests := c.requests() + if allRequests == 0 { + return 0 + } + return time.Duration(c.allTime.Load() / allRequests) +} + +func (c *clientStatusMonitor) requests() uint64 { + return c.allRequests.Load() } func (c *clientStatusMonitor) incRequests(elapsed time.Duration) { @@ -1909,6 +1918,7 @@ func (p Pool) Statistic() Statistic { node := &NodeStatistic{ address: cl.address(), latency: cl.latency(), + requests: cl.requests(), overallErrors: cl.overallErrorRate(), currentErrors: cl.currentErrorRate(), } diff --git a/pool/statistic.go b/pool/statistic.go index f7256a84..89e228e6 100644 --- a/pool/statistic.go +++ b/pool/statistic.go @@ -40,6 +40,7 @@ func (s Statistic) Node(address string) (*NodeStatistic, error) { type NodeStatistic struct { address string latency time.Duration + requests uint64 overallErrors uint64 currentErrors uint32 } @@ -61,6 +62,11 @@ func (n NodeStatistic) Latency() time.Duration { return n.latency } +// Requests returns number of requests. +func (n NodeStatistic) Requests() uint64 { + return n.requests +} + // Address returns node endpoint address. func (n NodeStatistic) Address() string { return n.address