12
respInfo map[int16]uint32
15
func NewRecords() *Records {
17
respInfo: map[int16]uint32{},
22
func (r *Records) RecordResponse(statuscode int16) {
24
defer r.mutex.Unlock()
25
if _, ok := r.respInfo[statuscode]; !ok {
26
r.respInfo[statuscode] = 0
28
r.respInfo[statuscode] += 1
31
func (r *Records) RecordRequest() {
32
atomic.AddUint32(&r.reqTotal, 1)
35
func (r *Records) ResponseInfo() (map[int16]uint32, uint32) {
37
defer r.mutex.Unlock()
39
m := make(map[int16]uint32, len(r.respInfo))
40
for k, v := range r.respInfo {
47
func (r *Records) Requests() uint32 {
48
return atomic.LoadUint32(&r.reqTotal)
51
func (r *Records) String() string {
52
info, total := r.ResponseInfo()
53
return fmt.Sprintf("request: %d, response total: %d, response status: %v", r.Requests(), total, info)
56
type ServerStats struct {
57
connectionTotal uint32
58
connectionActive uint32
59
connectionClosed uint32
63
type ServerStatsReadOnly interface {
64
ConnectionTotal() uint32
65
ConnectionActive() uint32
66
ConnectionClosed() uint32
68
ResponseInfo() (map[int16]uint32, uint32)
72
func NewServerStats() *ServerStats {
74
records: NewRecords(),
78
func (s *ServerStats) ConnectionTotal() uint32 {
79
return atomic.LoadUint32(&s.connectionTotal)
82
func (s *ServerStats) ConnectionActive() uint32 {
83
return atomic.LoadUint32(&s.connectionActive)
86
func (s *ServerStats) ConnectionClosed() uint32 {
87
return atomic.LoadUint32(&s.connectionClosed)
90
func (s *ServerStats) Records() *Records {
94
func (s *ServerStats) ResponseInfo() (map[int16]uint32, uint32) {
95
return s.records.ResponseInfo()
97
func (s *ServerStats) Requests() uint32 {
98
return s.records.Requests()
101
func (s *ServerStats) ActiveConnection() {
102
atomic.AddUint32(&s.connectionTotal, 1)
103
atomic.AddUint32(&s.connectionActive, 1)
106
func (s *ServerStats) CloseConnection() {
108
atomic.AddUint32(&s.connectionActive, ^uint32(0))
109
atomic.AddUint32(&s.connectionClosed, 1)
112
func (s *ServerStats) String() string {
113
return fmt.Sprintf("connections: { total: %d, actvie: %d, closed: %d}, response info: %s",
114
s.ConnectionTotal(), s.ConnectionActive(), s.ConnectionClosed(), s.Records().String())
117
type ClientStatsReadOnly interface {
119
ExpectedResponseCount() uint32
120
UnexpectedResponseCount() uint32
123
type ClientStats struct {
125
expectedResponse uint32
126
unexpectedResponse uint32
129
func NewClientStats() *ClientStats {
131
ServerStats: NewServerStats(),
135
func (c *ClientStats) ExpectedResponseCount() uint32 {
136
return atomic.LoadUint32(&c.expectedResponse)
139
func (c *ClientStats) UnexpectedResponseCount() uint32 {
140
return atomic.LoadUint32(&c.unexpectedResponse)
143
func (c *ClientStats) Response(expected bool) {
145
atomic.AddUint32(&c.expectedResponse, 1)
147
atomic.AddUint32(&c.unexpectedResponse, 1)
151
func (c *ClientStats) String() string {
152
return fmt.Sprintf("%s, expected response: %d, unexpected response: %d", c.ServerStats.String(), c.ExpectedResponseCount(), c.UnexpectedResponseCount())