server/stats_generic.go

89 lines
2.4 KiB
Go
Raw Permalink Normal View History

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