state.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package entry
  2. import "sync"
  3. type State struct {
  4. mutex sync.Mutex
  5. Accepting int32 `json:"accepting"` //是否正在接收连接
  6. Processing int32 `json:"processing"` //是否正在处理连接
  7. Concurrency int32 `json:"concurrency"`
  8. Request struct {
  9. Total int64 `json:"total"` //总处理请求
  10. Processed int64 `json:"processed"` //处理完成的请求
  11. Discarded int64 `json:"discarded"` //丢弃的请求
  12. } `json:"request"`
  13. Traffic struct {
  14. In int64 `json:"in"` //入网流量
  15. Out int64 `json:"out"` //出网流量
  16. } `json:"traffic"`
  17. }
  18. func (s *State) IncRequest(n int64) {
  19. s.mutex.Lock()
  20. s.Request.Total += n
  21. s.mutex.Unlock()
  22. }
  23. func (s *State) IncRequestProcessed(n int64) {
  24. s.mutex.Lock()
  25. s.Request.Processed += n
  26. s.mutex.Unlock()
  27. }
  28. func (s *State) IncRequestDiscarded(n int64) {
  29. s.mutex.Lock()
  30. s.Request.Discarded += n
  31. s.mutex.Unlock()
  32. }
  33. func (s *State) IncTrafficIn(n int64) {
  34. s.mutex.Lock()
  35. s.Traffic.In += n
  36. s.mutex.Unlock()
  37. }
  38. func (s *State) IncTrafficOut(n int64) {
  39. s.mutex.Lock()
  40. s.Traffic.Out += n
  41. s.mutex.Unlock()
  42. }