英文:
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.MemStats
和debug.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
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论