server/stats_386.go

107 lines
1.9 KiB
Go
Raw Permalink Normal View History

2017-10-26 11:14:00 +00:00
package server
import "sync"
// Snapshot returns connection statistics' snapshot.
//
2017-11-01 05:22:52 +00:00
// Use stats returned from ServerStats.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-11-01 05:22:52 +00:00
func (ss *ServerStats) Snapshot() *ServerStats {
ss.lock.Lock()
snapshot := *ss
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
snapshot.lock = sync.Mutex{}
return &snapshot
}
// Reset resets all the stats counters.
2017-11-01 05:22:52 +00:00
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()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incRPCCalls() {
ss.lock.Lock()
ss.RequestCount++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incRPCTime(dt uint64) {
ss.lock.Lock()
ss.RequestTime += dt
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) addBytesWritten(n uint64) {
ss.lock.Lock()
ss.BytesWritten += n
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) addBytesRead(n uint64) {
ss.lock.Lock()
ss.BytesRead += n
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incReadCalls() {
ss.lock.Lock()
ss.ReadCalls++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incReadErrors() {
ss.lock.Lock()
ss.ReadErrors++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incWriteCalls() {
ss.lock.Lock()
ss.WriteCalls++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incWriteErrors() {
ss.lock.Lock()
ss.WriteErrors++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incDialCalls() {
ss.lock.Lock()
ss.DialCalls++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incDialErrors() {
ss.lock.Lock()
ss.DialErrors++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incAcceptCalls() {
ss.lock.Lock()
ss.AcceptCalls++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}
2017-11-01 05:22:52 +00:00
func (ss *ServerStats) incAcceptErrors() {
ss.lock.Lock()
ss.AcceptErrors++
ss.lock.Unlock()
2017-10-26 11:14:00 +00:00
}