【发布时间】:2021-05-18 01:23:44
【问题描述】:
我已经从我的 Go 应用程序中公开了默认指标和一些自定义指标。 我可以在浏览器中查看指标:
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes ***********
我希望能够从我的应用程序代码中访问这些指标,也许可以查询它们。 我一直在研究 prometheus 和 prometheus HTTP API 的 client_golang 包,但找不到我的方法。
如何做到这一点?
【问题讨论】:
-
当你说你使用HTTP API时,你是查询客户端(即
localhost,还是收集指标的Prometheus服务器?你需要调用服务器上的API。如果你不想进行外部调用,您可以在本地安装服务器,从 localhost 抓取并调用本地托管服务器上的 API。或者只需在代码中调用端点并解析go_memstats_alloc_bytes。
标签: go prometheus metrics