server/stats_generic.go

89 lines
2.4 KiB
Go
Raw Normal View History

2017-10-26 11:14:00 +00:00
package server
import "sync/atomic"
// 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 {
return &ConnStats{
RequestCount: atomic.LoadUint64(&cs.RequestCount),
RequestTime: atomic.LoadUint64(&cs.RequestTime),
BytesWritten: atomic.LoadUint64(&cs.BytesWritten),
BytesRead: atomic.LoadUint64(&cs.BytesRead),
ReadCalls: atomic.LoadUint64(&cs.ReadCalls),
ReadErrors: atomic.LoadUint64(&cs.ReadErrors),
WriteCalls: atomic.LoadUint64(&cs.WriteCalls),
WriteErrors: atomic.LoadUint64(&cs.WriteErrors),
DialCalls: atomic.LoadUint64(&cs.DialCalls),
DialErrors: atomic.LoadUint64(&cs.DialErrors),
AcceptCalls: atomic.LoadUint64(&cs.AcceptCalls),
AcceptErrors: atomic.LoadUint64(&cs.AcceptErrors),
2017-10-26 11:14:00 +00:00
}
}
// Reset resets all the stats counters.
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) Reset() {
atomic.StoreUint64(&cs.RequestCount, 0)
atomic.StoreUint64(&cs.RequestTime, 0)
atomic.StoreUint64(&cs.BytesWritten, 0)
atomic.StoreUint64(&cs.BytesRead, 0)
atomic.StoreUint64(&cs.WriteCalls, 0)
atomic.StoreUint64(&cs.WriteErrors, 0)
atomic.StoreUint64(&cs.ReadCalls, 0)
atomic.StoreUint64(&cs.ReadErrors, 0)
atomic.StoreUint64(&cs.DialCalls, 0)
atomic.StoreUint64(&cs.DialErrors, 0)
atomic.StoreUint64(&cs.AcceptCalls, 0)
atomic.StoreUint64(&cs.AcceptErrors, 0)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incRPCCalls() {
atomic.AddUint64(&cs.RequestCount, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incRPCTime(dt uint64) {
atomic.AddUint64(&cs.RequestTime, dt)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) addBytesWritten(n uint64) {
atomic.AddUint64(&cs.BytesWritten, n)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) addBytesRead(n uint64) {
atomic.AddUint64(&cs.BytesRead, n)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incReadCalls() {
atomic.AddUint64(&cs.ReadCalls, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incReadErrors() {
atomic.AddUint64(&cs.ReadErrors, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incWriteCalls() {
atomic.AddUint64(&cs.WriteCalls, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incWriteErrors() {
atomic.AddUint64(&cs.WriteErrors, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incDialCalls() {
atomic.AddUint64(&cs.DialCalls, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incDialErrors() {
atomic.AddUint64(&cs.DialErrors, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incAcceptCalls() {
atomic.AddUint64(&cs.AcceptCalls, 1)
2017-10-26 11:14:00 +00:00
}
2017-10-26 12:08:50 +00:00
func (cs *ConnStats) incAcceptErrors() {
atomic.AddUint64(&cs.AcceptErrors, 1)
2017-10-26 11:14:00 +00:00
}