107 lines
1.9 KiB
Go
107 lines
1.9 KiB
Go
package server
|
|
|
|
import "sync"
|
|
|
|
// 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 {
|
|
ss.lock.Lock()
|
|
snapshot := *ss
|
|
ss.lock.Unlock()
|
|
|
|
snapshot.lock = sync.Mutex{}
|
|
return &snapshot
|
|
}
|
|
|
|
// Reset resets all the stats counters.
|
|
func (ss *ServerStats) Reset() {
|
|
ss.lock.Lock()
|
|
ss.RequestCount = 0
|
|
ss.RequestTime = 0
|
|
ss.BytesWritten = 0
|
|
ss.BytesRead = 0
|
|
ss.WriteCalls = 0
|
|
ss.WriteErrors = 0
|
|
ss.ReadCalls = 0
|
|
ss.ReadErrors = 0
|
|
ss.DialCalls = 0
|
|
ss.DialErrors = 0
|
|
ss.AcceptCalls = 0
|
|
ss.AcceptErrors = 0
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incRPCCalls() {
|
|
ss.lock.Lock()
|
|
ss.RequestCount++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incRPCTime(dt uint64) {
|
|
ss.lock.Lock()
|
|
ss.RequestTime += dt
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) addBytesWritten(n uint64) {
|
|
ss.lock.Lock()
|
|
ss.BytesWritten += n
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) addBytesRead(n uint64) {
|
|
ss.lock.Lock()
|
|
ss.BytesRead += n
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incReadCalls() {
|
|
ss.lock.Lock()
|
|
ss.ReadCalls++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incReadErrors() {
|
|
ss.lock.Lock()
|
|
ss.ReadErrors++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incWriteCalls() {
|
|
ss.lock.Lock()
|
|
ss.WriteCalls++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incWriteErrors() {
|
|
ss.lock.Lock()
|
|
ss.WriteErrors++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incDialCalls() {
|
|
ss.lock.Lock()
|
|
ss.DialCalls++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incDialErrors() {
|
|
ss.lock.Lock()
|
|
ss.DialErrors++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incAcceptCalls() {
|
|
ss.lock.Lock()
|
|
ss.AcceptCalls++
|
|
ss.lock.Unlock()
|
|
}
|
|
|
|
func (ss *ServerStats) incAcceptErrors() {
|
|
ss.lock.Lock()
|
|
ss.AcceptErrors++
|
|
ss.lock.Unlock()
|
|
}
|