Add Metrics (Fix: #21)
the build was successful Details

This commit is contained in:
Sarah Jamie Lewis 2020-07-14 16:35:21 -07:00
parent 28b2f8212f
commit f26a98895a
2 changed files with 26 additions and 0 deletions

View File

@ -23,6 +23,26 @@ type BaseOnionService struct {
lock sync.Mutex
}
// Metrics provides a report of useful information about the status of the service e.g. the number of active
// connections
func (s *BaseOnionService) Metrics() tapir.ServiceMetrics {
s.lock.Lock()
defer s.lock.Unlock()
count := 0
s.connections.Range(func(key, value interface{}) bool {
connection := value.(tapir.Connection)
if !connection.IsClosed() {
count++
}
return true
})
return tapir.ServiceMetrics{
ConnectionCount: count,
}
}
// Init initializes a BaseOnionService with a given private key and identity
// The private key is needed to initialize the Onion listen socket, ideally we could just pass an Identity in here.
func (s *BaseOnionService) Init(acn connectivity.ACN, sk ed25519.PrivateKey, id *primitives.Identity) {

View File

@ -12,12 +12,18 @@ import (
"sync"
)
// ServiceMetrics outlines higher level information about the service e.g. counts of connections
type ServiceMetrics struct {
ConnectionCount int
}
// Service defines the interface for a Tapir Service
type Service interface {
Init(acn connectivity.ACN, privateKey ed25519.PrivateKey, identity *primitives.Identity)
Connect(hostname string, application Application) (bool, error)
Listen(application Application) error
GetConnection(connectionID string) (Connection, error)
Metrics() ServiceMetrics
Broadcast(message []byte, capability Capability) error
WaitForCapabilityOrClose(connectionID string, capability Capability) (Connection, error)
Shutdown()