You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/statistics/statistics.go

42 lines
1.0 KiB

3 years ago
package statistics
import (
"context"
2 years ago
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"time"
)
3 years ago
type Statistics struct {
3 years ago
AllCount *uint64
ModuleName string
PrintArgs string
3 years ago
SleepTime uint64
3 years ago
}
func (s *Statistics) output() {
3 years ago
var intervalCount uint64
t := time.NewTicker(time.Duration(s.SleepTime) * time.Second)
defer t.Stop()
var sum uint64
3 years ago
var timeIntervalNum uint64
3 years ago
for {
3 years ago
sum = *s.AllCount
select {
case <-t.C:
}
3 years ago
if *s.AllCount-sum <= 0 {
intervalCount = 0
} else {
intervalCount = *s.AllCount - sum
}
3 years ago
timeIntervalNum++
log.ZWarn(context.Background(), " system stat ", nil, "args", s.PrintArgs, "intervalCount", intervalCount, "total:", *s.AllCount, "intervalNum", timeIntervalNum, "avg", (*s.AllCount)/(timeIntervalNum)/s.SleepTime)
3 years ago
}
}
3 years ago
func NewStatistics(allCount *uint64, moduleName, printArgs string, sleepTime int) *Statistics {
3 years ago
p := &Statistics{AllCount: allCount, ModuleName: moduleName, SleepTime: uint64(sleepTime), PrintArgs: printArgs}
3 years ago
go p.output()
return p
3 years ago
}