44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
|
|
package starnet
|
||
|
|
|
||
|
|
import "sync/atomic"
|
||
|
|
|
||
|
|
// StatsSnapshot is a read-only copy of runtime counters.
|
||
|
|
type StatsSnapshot struct {
|
||
|
|
Accepted uint64
|
||
|
|
TLSDetected uint64
|
||
|
|
PlainDetected uint64
|
||
|
|
InitFailures uint64
|
||
|
|
Closed uint64
|
||
|
|
}
|
||
|
|
|
||
|
|
// Stats provides lock-free counters.
|
||
|
|
type Stats struct {
|
||
|
|
accepted uint64
|
||
|
|
tlsDetected uint64
|
||
|
|
plainDetected uint64
|
||
|
|
initFailures uint64
|
||
|
|
closed uint64
|
||
|
|
}
|
||
|
|
|
||
|
|
func (s *Stats) incAccepted() { atomic.AddUint64(&s.accepted, 1) }
|
||
|
|
func (s *Stats) incTLSDetected() { atomic.AddUint64(&s.tlsDetected, 1) }
|
||
|
|
func (s *Stats) incPlainDetected() { atomic.AddUint64(&s.plainDetected, 1) }
|
||
|
|
func (s *Stats) incInitFailures() { atomic.AddUint64(&s.initFailures, 1) }
|
||
|
|
func (s *Stats) incClosed() { atomic.AddUint64(&s.closed, 1) }
|
||
|
|
|
||
|
|
// Snapshot returns a stable view of counters.
|
||
|
|
func (s *Stats) Snapshot() StatsSnapshot {
|
||
|
|
return StatsSnapshot{
|
||
|
|
Accepted: atomic.LoadUint64(&s.accepted),
|
||
|
|
TLSDetected: atomic.LoadUint64(&s.tlsDetected),
|
||
|
|
PlainDetected: atomic.LoadUint64(&s.plainDetected),
|
||
|
|
InitFailures: atomic.LoadUint64(&s.initFailures),
|
||
|
|
Closed: atomic.LoadUint64(&s.closed),
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Logger is a minimal logging abstraction.
|
||
|
|
type Logger interface {
|
||
|
|
Printf(format string, v ...interface{})
|
||
|
|
}
|