server/stats_386.go

107 lines
1.8 KiB
Go
Raw Normal View History

2017-10-26 11:14:00 +00:00
package server
import "sync"
// Snapshot returns connection statistics' snapshot.
//
2017-10-26 12:08:50 +00:00
// Use stats returned from ConnStats.Snapshot() on live Client and / or Server,
2017-10-26 11:14:00 +00:00
// since the original stats can be updated by concurrently running goroutines.
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) Snapshot() *ConnStats {
cs.lock.Lock()
snapshot := *cs
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
snapshot.lock = sync.Mutex{}
return &snapshot
}
// Reset resets all the stats counters.
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) Reset() {
cs.lock.Lock()
cs.RequestCount = 0
cs.RequestTime = 0
cs.BytesWritten = 0
cs.BytesRead = 0
cs.WriteCalls = 0
cs.WriteErrors = 0
cs.ReadCalls = 0
cs.ReadErrors = 0
cs.DialCalls = 0
cs.DialErrors = 0
cs.AcceptCalls = 0
cs.AcceptErrors = 0
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incRPCCalls() {
cs.lock.Lock()
cs.RequestCount++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incRPCTime(dt uint64) {
cs.lock.Lock()
cs.RequestTime += dt
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) addBytesWritten(n uint64) {
cs.lock.Lock()
cs.BytesWritten += n
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) addBytesRead(n uint64) {
cs.lock.Lock()
cs.BytesRead += n
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incReadCalls() {
cs.lock.Lock()
cs.ReadCalls++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incReadErrors() {
cs.lock.Lock()
cs.ReadErrors++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incWriteCalls() {
cs.lock.Lock()
cs.WriteCalls++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incWriteErrors() {
cs.lock.Lock()
cs.WriteErrors++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incDialCalls() {
cs.lock.Lock()
cs.DialCalls++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incDialErrors() {
cs.lock.Lock()
cs.DialErrors++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incAcceptCalls() {
cs.lock.Lock()
cs.AcceptCalls++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incAcceptErrors() {
cs.lock.Lock()
cs.AcceptErrors++
cs.lock.Unlock()
2017-10-26 11:14:00 +00:00
}