【发布时间】:2021-05-19 09:11:50
【问题描述】:
我正在尝试使用 Golang 创建一个 REST API 来向 Prometheus 提供指标。我已经有可用的 REST API,例如:http://localhost:46743/prometheusJobs API 在 swagger 上测试后工作正常,我得到的响应内容如下,现在它只是我得到的文本格式示例来自 Prometheus 文档。
这是我的 Go 函数,用于向 Prometheus 输出(提供)指标,现在它只是一个字符串,我想先测试一下:
func GetPrometheusJobsHandler(params jobs_management.GetPrometheusJobsParams) middleware.Responder {
ret := ""
// TODO : construct metrics
ret += `
# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027 1395066363000
http_requests_total{method="post",code="400"} 3 1395066363000
`
return jobs_management.NewGetPrometheusJobsOK().WithPayload(ret)
}
在我的 Prometheus 中,我已成功连接到此 API,状态现在显示为 UP:
并且,该值显示为1
但是,在 Prometheus 的下拉菜单中,我没有看到我在上面的 Go 函数中定义为输出的字符串:
你能告诉我我做错了什么吗?或者这不是向 Prometheus 提供指标的正确方法,我必须使用 Golang 库 (https://github.com/prometheus/client_golang/)?非常感谢您。
【问题讨论】:
标签: go prometheus rest