89 lines
2.4 KiB
Go
89 lines
2.4 KiB
Go
|
package server
|
||
|
|
||
|
import "sync/atomic"
|
||
|
|
||
|
// Snapshot returns connection statistics' snapshot.
|
||
|
//
|
||
|
// Use stats returned from ServerStats.Snapshot() on live Client and / or Server,
|
||
|
// since the original stats can be updated by concurrently running goroutines.
|
||
|
func (ss *ServerStats) Snapshot() *ServerStats {
|
||
|
return &ServerStats{
|
||
|
RequestCount: atomic.LoadUint64(&ss.RequestCount),
|
||
|
RequestTime: atomic.LoadUint64(&ss.RequestTime),
|
||
|
BytesWritten: atomic.LoadUint64(&ss.BytesWritten),
|
||
|
BytesRead: atomic.LoadUint64(&ss.BytesRead),
|
||
|
ReadCalls: atomic.LoadUint64(&ss.ReadCalls),
|
||
|
ReadErrors: atomic.LoadUint64(&ss.ReadErrors),
|
||
|
WriteCalls: atomic.LoadUint64(&ss.WriteCalls),
|
||
|
WriteErrors: atomic.LoadUint64(&ss.WriteErrors),
|
||
|
DialCalls: atomic.LoadUint64(&ss.DialCalls),
|
||
|
DialErrors: atomic.LoadUint64(&ss.DialErrors),
|
||
|
AcceptCalls: atomic.LoadUint64(&ss.AcceptCalls),
|
||
|
AcceptErrors: atomic.LoadUint64(&ss.AcceptErrors),
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Reset resets all the stats counters.
|
||
|
func (ss *ServerStats) Reset() {
|
||
|
atomic.StoreUint64(&ss.RequestCount, 0)
|
||
|
atomic.StoreUint64(&ss.RequestTime, 0)
|
||
|
atomic.StoreUint64(&ss.BytesWritten, 0)
|
||
|
atomic.StoreUint64(&ss.BytesRead, 0)
|
||
|
atomic.StoreUint64(&ss.WriteCalls, 0)
|
||
|
atomic.StoreUint64(&ss.WriteErrors, 0)
|
||
|
atomic.StoreUint64(&ss.ReadCalls, 0)
|
||
|
atomic.StoreUint64(&ss.ReadErrors, 0)
|
||
|
atomic.StoreUint64(&ss.DialCalls, 0)
|
||
|
atomic.StoreUint64(&ss.DialErrors, 0)
|
||
|
atomic.StoreUint64(&ss.AcceptCalls, 0)
|
||
|
atomic.StoreUint64(&ss.AcceptErrors, 0)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incRPCCalls() {
|
||
|
atomic.AddUint64(&ss.RequestCount, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incRPCTime(dt uint64) {
|
||
|
atomic.AddUint64(&ss.RequestTime, dt)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) addBytesWritten(n uint64) {
|
||
|
atomic.AddUint64(&ss.BytesWritten, n)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) addBytesRead(n uint64) {
|
||
|
atomic.AddUint64(&ss.BytesRead, n)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incReadCalls() {
|
||
|
atomic.AddUint64(&ss.ReadCalls, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incReadErrors() {
|
||
|
atomic.AddUint64(&ss.ReadErrors, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incWriteCalls() {
|
||
|
atomic.AddUint64(&ss.WriteCalls, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incWriteErrors() {
|
||
|
atomic.AddUint64(&ss.WriteErrors, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incDialCalls() {
|
||
|
atomic.AddUint64(&ss.DialCalls, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incDialErrors() {
|
||
|
atomic.AddUint64(&ss.DialErrors, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incAcceptCalls() {
|
||
|
atomic.AddUint64(&ss.AcceptCalls, 1)
|
||
|
}
|
||
|
|
||
|
func (ss *ServerStats) incAcceptErrors() {
|
||
|
atomic.AddUint64(&ss.AcceptErrors, 1)
|
||
|
}
|