wtclient+lnrpc: move Stats to Manager
Move the `Stats` method from the `Client` to the `Manager` interface.
This commit is contained in:
3 files changed
+25
-18
No files matched your search
@@ -420,19 +420,7 @@ func (c *WatchtowerClient) Stats(_ context.Context,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
clientStats := []wtclient.ClientStats{
|
stats := c.cfg.ClientMgr.Stats()
|
||||||
c.cfg.Client.Stats(),
|
|
||||||
c.cfg.AnchorClient.Stats(),
|
|
||||||
}
|
|
||||||
|
|
||||||
var stats wtclient.ClientStats
|
|
||||||
for _, stat := range clientStats {
|
|
||||||
stats.NumTasksAccepted += stat.NumTasksAccepted
|
|
||||||
stats.NumTasksIneligible += stat.NumTasksIneligible
|
|
||||||
stats.NumTasksPending += stat.NumTasksPending
|
|
||||||
stats.NumSessionsAcquired += stat.NumSessionsAcquired
|
|
||||||
stats.NumSessionsExhausted += stat.NumSessionsExhausted
|
|
||||||
}
|
|
||||||
|
|
||||||
return &StatsResponse{
|
return &StatsResponse{
|
||||||
NumBackups: uint32(stats.NumTasksAccepted),
|
NumBackups: uint32(stats.NumTasksAccepted),
|
||||||
|
|||||||
@@ -104,9 +104,6 @@ type Client interface {
|
|||||||
LookupTower(*btcec.PublicKey,
|
LookupTower(*btcec.PublicKey,
|
||||||
...wtdb.ClientSessionListOption) (*RegisteredTower, error)
|
...wtdb.ClientSessionListOption) (*RegisteredTower, error)
|
||||||
|
|
||||||
// Stats returns the in-memory statistics of the client since startup.
|
|
||||||
Stats() ClientStats
|
|
||||||
|
|
||||||
// Policy returns the active client policy configuration.
|
// Policy returns the active client policy configuration.
|
||||||
Policy() wtpolicy.Policy
|
Policy() wtpolicy.Policy
|
||||||
|
|
||||||
@@ -1635,8 +1632,8 @@ func (c *TowerClient) LookupTower(pubKey *btcec.PublicKey,
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stats returns the in-memory statistics of the client since startup.
|
// getStats returns the in-memory statistics of the client since startup.
|
||||||
func (c *TowerClient) Stats() ClientStats {
|
func (c *TowerClient) getStats() ClientStats {
|
||||||
return c.stats.getStatsCopy()
|
return c.stats.getStatsCopy()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ type TowerClientManager interface {
|
|||||||
// only serves as a way of removing the address from the watchtower
|
// only serves as a way of removing the address from the watchtower
|
||||||
// instead.
|
// instead.
|
||||||
RemoveTower(*btcec.PublicKey, net.Addr) error
|
RemoveTower(*btcec.PublicKey, net.Addr) error
|
||||||
|
|
||||||
|
// Stats returns the in-memory statistics of the client since startup.
|
||||||
|
Stats() ClientStats
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config provides the TowerClient with access to the resources it requires to
|
// Config provides the TowerClient with access to the resources it requires to
|
||||||
@@ -299,3 +302,22 @@ func (m *Manager) RemoveTower(key *btcec.PublicKey, addr net.Addr) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stats returns the in-memory statistics of the clients managed by the Manager
|
||||||
|
// since startup.
|
||||||
|
func (m *Manager) Stats() ClientStats {
|
||||||
|
m.clientsMu.Lock()
|
||||||
|
defer m.clientsMu.Unlock()
|
||||||
|
|
||||||
|
var resp ClientStats
|
||||||
|
for _, client := range m.clients {
|
||||||
|
stats := client.getStats()
|
||||||
|
resp.NumTasksAccepted += stats.NumTasksAccepted
|
||||||
|
resp.NumTasksIneligible += stats.NumTasksIneligible
|
||||||
|
resp.NumTasksPending += stats.NumTasksPending
|
||||||
|
resp.NumSessionsAcquired += stats.NumSessionsAcquired
|
||||||
|
resp.NumSessionsExhausted += stats.NumSessionsExhausted
|
||||||
|
}
|
||||||
|
|
||||||
|
return resp
|
||||||
|
}
|
||||||
Reference in new issue
Block a user