kos/entry/state.go

50 lines
1.1 KiB
Go
Raw Normal View History

2023-04-23 17:57:36 +08:00
package entry
2023-06-11 11:19:01 +08:00
import "sync"
2023-04-23 17:57:36 +08:00
type State struct {
2023-06-11 11:19:01 +08:00
mutex sync.Mutex
2023-04-23 17:57:36 +08:00
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"`
}
2023-06-11 11:19:01 +08:00
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()
}