dongwen7730 2015-06-10 15:40
浏览 40

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)
}
  • 写回答

1条回答 默认 最新

  • donxbje866688 2016-03-09 07:29
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分