2019-03-15 12:32:15 +03:00
|
|
|
package wtclient
|
|
|
|
|
2019-06-08 03:46:15 +03:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"sync"
|
|
|
|
)
|
2019-03-15 12:32:15 +03:00
|
|
|
|
2019-06-08 03:45:58 +03:00
|
|
|
// ClientStats is a collection of in-memory statistics of the actions the client
|
|
|
|
// has performed since its creation.
|
|
|
|
type ClientStats struct {
|
2019-06-08 03:46:15 +03:00
|
|
|
mu sync.Mutex
|
|
|
|
|
2019-06-08 03:45:58 +03:00
|
|
|
// NumTasksReceived is the total number of backups that are pending to
|
|
|
|
// be acknowledged by all active and exhausted watchtower sessions.
|
|
|
|
NumTasksReceived int
|
|
|
|
|
|
|
|
// NumTasksAccepted is the total number of backups made to all active
|
|
|
|
// and exhausted watchtower sessions.
|
|
|
|
NumTasksAccepted int
|
|
|
|
|
|
|
|
// NumTasksIneligible is the total number of backups that all active and
|
|
|
|
// exhausted watchtower sessions have failed to acknowledge.
|
|
|
|
NumTasksIneligible int
|
|
|
|
|
|
|
|
// NumSessionsAcquired is the total number of new sessions made to
|
|
|
|
// watchtowers.
|
|
|
|
NumSessionsAcquired int
|
|
|
|
|
|
|
|
// NumSessionsExhausted is the total number of watchtower sessions that
|
|
|
|
// have been exhausted.
|
|
|
|
NumSessionsExhausted int
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// taskReceived increments the number to backup requests the client has received
|
|
|
|
// from active channels.
|
2019-06-08 03:45:58 +03:00
|
|
|
func (s *ClientStats) taskReceived() {
|
2019-06-08 03:46:15 +03:00
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2019-06-08 03:45:58 +03:00
|
|
|
s.NumTasksReceived++
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// taskAccepted increments the number of tasks that have been assigned to active
|
|
|
|
// session queues, and are awaiting upload to a tower.
|
2019-06-08 03:45:58 +03:00
|
|
|
func (s *ClientStats) taskAccepted() {
|
2019-06-08 03:46:15 +03:00
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2019-06-08 03:45:58 +03:00
|
|
|
s.NumTasksAccepted++
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// taskIneligible increments the number of tasks that were unable to satisfy the
|
|
|
|
// active session queue's policy. These can potentially be retried later, but
|
|
|
|
// typically this means that the balance created dust outputs, so it may not be
|
|
|
|
// worth backing up at all.
|
2019-06-08 03:45:58 +03:00
|
|
|
func (s *ClientStats) taskIneligible() {
|
2019-06-08 03:46:15 +03:00
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2019-06-08 03:45:58 +03:00
|
|
|
s.NumTasksIneligible++
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// sessionAcquired increments the number of sessions that have been successfully
|
|
|
|
// negotiated by the client during this execution.
|
2019-06-08 03:45:58 +03:00
|
|
|
func (s *ClientStats) sessionAcquired() {
|
2019-06-08 03:46:15 +03:00
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2019-06-08 03:45:58 +03:00
|
|
|
s.NumSessionsAcquired++
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// sessionExhausted increments the number of session that have become full as a
|
|
|
|
// result of accepting backup tasks.
|
2019-06-08 03:45:58 +03:00
|
|
|
func (s *ClientStats) sessionExhausted() {
|
2019-06-08 03:46:15 +03:00
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2019-06-08 03:45:58 +03:00
|
|
|
s.NumSessionsExhausted++
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// String returns a human readable summary of the client's metrics.
|
2019-06-08 03:46:15 +03:00
|
|
|
func (s *ClientStats) String() string {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
2019-03-15 12:32:15 +03:00
|
|
|
return fmt.Sprintf("tasks(received=%d accepted=%d ineligible=%d) "+
|
2019-06-08 03:45:58 +03:00
|
|
|
"sessions(acquired=%d exhausted=%d)", s.NumTasksReceived,
|
|
|
|
s.NumTasksAccepted, s.NumTasksIneligible, s.NumSessionsAcquired,
|
|
|
|
s.NumSessionsExhausted)
|
2019-03-15 12:32:15 +03:00
|
|
|
}
|
2019-06-08 03:46:15 +03:00
|
|
|
|
|
|
|
// Copy returns a copy of the current stats.
|
|
|
|
func (s *ClientStats) Copy() ClientStats {
|
|
|
|
s.mu.Lock()
|
|
|
|
defer s.mu.Unlock()
|
|
|
|
return ClientStats{
|
|
|
|
NumTasksReceived: s.NumTasksReceived,
|
|
|
|
NumTasksAccepted: s.NumTasksAccepted,
|
|
|
|
NumTasksIneligible: s.NumTasksIneligible,
|
|
|
|
NumSessionsAcquired: s.NumSessionsAcquired,
|
|
|
|
NumSessionsExhausted: s.NumSessionsExhausted,
|
|
|
|
}
|
|
|
|
}
|