[#283] pool: Add number of requests to statistic

Signed-off-by: Denis Kirillov <denis@nspcc.ru>
This commit is contained in:
Denis Kirillov 2022-07-13 13:16:55 +03:00 committed by fyrchik
parent 1b30d228da
commit 0b8c53ebc9
2 changed files with 17 additions and 1 deletions

View file

@ -62,6 +62,7 @@ type clientStatus interface {
overallErrorRate() uint64 overallErrorRate() uint64
resetErrorCounter() resetErrorCounter()
latency() time.Duration latency() time.Duration
requests() uint64
} }
type clientStatusMonitor struct { type clientStatusMonitor struct {
@ -572,7 +573,15 @@ func (c *clientStatusMonitor) resetErrorCounter() {
} }
func (c *clientStatusMonitor) latency() time.Duration { 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) { func (c *clientStatusMonitor) incRequests(elapsed time.Duration) {
@ -1909,6 +1918,7 @@ func (p Pool) Statistic() Statistic {
node := &NodeStatistic{ node := &NodeStatistic{
address: cl.address(), address: cl.address(),
latency: cl.latency(), latency: cl.latency(),
requests: cl.requests(),
overallErrors: cl.overallErrorRate(), overallErrors: cl.overallErrorRate(),
currentErrors: cl.currentErrorRate(), currentErrors: cl.currentErrorRate(),
} }

View file

@ -40,6 +40,7 @@ func (s Statistic) Node(address string) (*NodeStatistic, error) {
type NodeStatistic struct { type NodeStatistic struct {
address string address string
latency time.Duration latency time.Duration
requests uint64
overallErrors uint64 overallErrors uint64
currentErrors uint32 currentErrors uint32
} }
@ -61,6 +62,11 @@ func (n NodeStatistic) Latency() time.Duration {
return n.latency return n.latency
} }
// Requests returns number of requests.
func (n NodeStatistic) Requests() uint64 {
return n.requests
}
// Address returns node endpoint address. // Address returns node endpoint address.
func (n NodeStatistic) Address() string { func (n NodeStatistic) Address() string {
return n.address return n.address