Files
origin/service/DeadForMonitor.go
duanhf2012 4c6d72fd65 1.websocket接受消息,每15秒监控最大耗时消息类型,某消息处理超过300ms会有监控日志
2.GoQueue处理队列监控,每1分钟汇报积压处理的最大量。并监控死循环
2020-02-25 16:36:43 +08:00

78 lines
1.5 KiB
Go

package service
import (
"fmt"
"github.com/duanhf2012/origin/util"
"runtime/pprof"
"time"
)
type ModuleMontior struct {
mapModule *util.MapEx
}
type ModuleInfo struct {
enterStartTm int64
mNameInfo string
}
var moduleMontior ModuleMontior
func MonitorEnter(uuid string,strMonitorInfo string){
if moduleMontior.mapModule == nil {
return
}
moduleMontior.mapModule.Set(uuid, &ModuleInfo{enterStartTm:time.Now().Unix(),mNameInfo:strMonitorInfo})
}
func MonitorLeave(uuid string){
if moduleMontior.mapModule == nil {
return
}
moduleMontior.mapModule.Del(uuid)
}
func ReportDeadFor(){
if moduleMontior.mapModule == nil {
return
}
moduleMontior.mapModule.RLockRange(func(key interface{}, value interface{}) {
if value != nil {
pModuleInfo := value.(*ModuleInfo)
//超过5分钟认为dead for
if time.Now().Unix() - pModuleInfo.enterStartTm > 300 {
GetLogger().Printf(LEVER_FATAL, "module is %s, Dead cycle\n", pModuleInfo.mNameInfo)
}
}
})
}
func EnableDeadForMonitor(checkInterval time.Duration){
moduleMontior.mapModule = util.NewMapEx()
var tmInval util.Timer
tmInval.SetupTimer(int32(checkInterval.Milliseconds()))
go func(){
for {
time.Sleep(time.Second*5)
if tmInval.CheckTimeOut(){
ReportDeadFor()
ReportPprof()
}
}
}()
}
func ReportPprof(){
strReport := ""
for _, p := range pprof.Profiles() {
strReport += fmt.Sprintf("Name %s,count %d\n",p.Name(),p.Count())
}
GetLogger().Printf(LEVER_INFO, "PProf %s\n", strReport)
}