wtclient+lnrpc: move Stats to Manager

Move the `Stats` method from the `Client` to the `Manager` interface.
This commit is contained in:
Elle Mouton committed 2023-11-28 09:54:02 +02:00
1 parent f38b5cf258
commit 4348f2062a
3 files changed
+25 -18

No files matched your search

+22
View File
@@ -33,6 +33,9 @@ type TowerClientManager interface {
// only serves as a way of removing the address from the watchtower
// instead.
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
@@ -299,3 +302,22 @@ func (m *Manager) RemoveTower(key *btcec.PublicKey, addr net.Addr) error {
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
}