我使用 gocraft / health 来检查我的服务的运行状况,并获得每个endPoint的指标。但我有一个问题: 启动我的服务仅用了5个小时后CPU达到100%我不知道为什么。 不使用" gocraft / health "它只占CPU的0.7%
之前有没有人使用过这个包var stream = health.NewStream()
func main() {
// Log to stdout! (can also use WriterSink to write to a log file, Syslog, etc)
stream.AddSink(&health.WriterSink{os.Stdout})
http.HandleFunc("/api/getVastPlayer", vastPlayer)
http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:])
})
log.Println("Listening...")
panic(http.ListenAndServe(":2001", nil))
}
func vastPlayer(w http.ResponseWriter, r *http.Request) {
job_1 := stream.NewJob("/api/getVastPlayer")
//job_2 := stream.NewJob("/api/html/")
sink := health.NewJsonPollingSink(time.Minute*5, time.Minute*5)
stream.AddSink(sink)
//http://creative.health.spoti.io/health
adr:="127.0.0.1:5001"
sink.StartServer(adr)
......
......
if bol{
job_1.Complete(health.Success)
}
else{
job_1.Complete(health.ValidationError)
}
答案 0 :(得分:0)
我认为这是正确的代码:
var stream = health.NewStream()
func main() {
// Log to stdout! (can also use WriterSink to write to a log file, Syslog, etc)
stream.AddSink(&health.WriterSink{os.Stdout})
sink := health.NewJsonPollingSink(time.Minute*5, time.Minute*5)
stream.AddSink(sink)
//http://creative.health.spoti.io/health
adr:="127.0.0.1:5001"
sink.StartServer(adr)
http.HandleFunc("/api/getVastPlayer", vastPlayer)
http.HandleFunc("/static/", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, r.URL.Path[1:])
})
log.Println("Listening...")
panic(http.ListenAndServe(":2001", nil))
}
func vastPlayer(w http.ResponseWriter, r *http.Request) {
job_1 := stream.NewJob("/api/getVastPlayer")
//job_2 := stream.NewJob("/api/html/")
......
......
if bol{
job_1.Complete(health.Success)
}
else{
job_1.Complete(health.ValidationError)
}
}