package entry import "sync" type State struct { mutex sync.Mutex Accepting int32 `json:"accepting"` //是否正在接收连接 Processing int32 `json:"processing"` //是否正在处理连接 Concurrency int32 `json:"concurrency"` Request struct { Total int64 `json:"total"` //总处理请求 Processed int64 `json:"processed"` //处理完成的请求 Discarded int64 `json:"discarded"` //丢弃的请求 } `json:"request"` Traffic struct { In int64 `json:"in"` //入网流量 Out int64 `json:"out"` //出网流量 } `json:"traffic"` } func (s *State) IncRequest(n int64) { s.mutex.Lock() s.Request.Total += n s.mutex.Unlock() } func (s *State) IncRequestProcessed(n int64) { s.mutex.Lock() s.Request.Processed += n s.mutex.Unlock() } func (s *State) IncRequestDiscarded(n int64) { s.mutex.Lock() s.Request.Discarded += n s.mutex.Unlock() } func (s *State) IncTrafficIn(n int64) { s.mutex.Lock() s.Traffic.In += n s.mutex.Unlock() } func (s *State) IncTrafficOut(n int64) { s.mutex.Lock() s.Traffic.Out += n s.mutex.Unlock() }