简体   繁体   中英

Golang : gocraft/health package 100% CPU

Im using gocraft/health to check the health of my service and have the metrics of each endPoint. But I have a problem: the CPU reach 100% after just 5 hours of starting my service I dont know why. without using the " gocraft/health " it takes just 0,7% of CPU does anyone worked with this pack before

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)
}

I think it's right code:

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)
}

}

PS: https://github.com/gocraft/health#jobs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM