![](/img/trans.png)
[英]Golang: healthd and healthtop of the library "gocraft/health"
[英]Golang : gocraft/health package 100% CPU
我使用gocraft / health來檢查我的服務的運行狀況,並獲得每個端點的指標。 但是我有一個問題:啟動服務僅5個小時,CPU達到100%,我不知道為什么。 如果不使用“ gocraft / health ”,那么任何人使用此軟件包僅需要0,7%的CPU
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)
}
我認為這是正確的代碼:
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)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.