收集实时的GC指标 – Golang

huangapple go评论78阅读模式
英文:

Collect real time GC metrics - Golang

问题

在Go语言中,有没有一种简单的方法可以获取有关垃圾回收(GC)和堆大小的信息,以便将它们暴露给监控仪表板?我查看了runtime包,但似乎没有任何可以实现这一功能的内容。理想情况下,这不应该需要任何额外的开销,比如在性能分析模式下运行应用程序等,而且应该是适用于生产环境的。

英文:

Is there a straightforward way in Go to get information about the GC and heap sizes in order to expose them to a monitoring dashboard. I had a look at the runtime package but there doesnt seem to be anything that does that there. Ideally this shouldnt require any overhead like running the application in profiling mode, etc, but should be production ready.

答案1

得分: 7

你可以使用GODEBUG=gctrace=1来获取连续的输出,这在runtime包中有详细说明。

否则,你需要从runtime.MemStatsdebug.GCStats中收集信息。

英文:

You can use the GODEBUG=gctrace=1 to get continuous output, which is documented in the runtime package.

Otherwise, you need to collect information from runtime.MemStats and debug.GCStats.

huangapple
  • 本文由 发表于 2015年12月4日 01:36:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/34072626.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定