Golang : gocraft/health package 100% CPU

507 views Asked by At

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

There are 1 answers

0
Valeriy Solovyov On

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