簡體   English   中英

在 Prometheus 中看不到來自 Golang REST API 的字符串指標 output

[英]Cannot see the string metrics output from Golang REST API in Prometheus

我正在嘗試使用 Golang 創建一個 REST API 以向 Prometheus 提供指標。 I already have REST API available that is available on for example: http://localhost:46743/prometheusJobs The API works fine after testing on swagger, I get the response content as followed, for now it's just the sample of text format I got來自普羅米修斯文檔。

昂首闊步

這是我的 Go function 到 output(提供)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,因為 state 現在顯示為UP

目標

並且,該值顯示為1

目標2

但是,我在普羅米修斯的下拉列表中沒有看到我在 Go function 上面定義為 output 的字符串:

下拉舞會

你能告訴我我做錯了什么嗎? 或者這不是向 Prometheus 提供指標的正確方法,我必須使用 Golang 庫( https://github.com/prometheus/client_golang/ )? 非常感謝您提前。

我認為這些不是有效的普羅米修斯指標:

# 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

你可以試試:

# HELP http_requests_total The total number of HTTP requests.
# TYPE http_requests_total counter
http_requests_total{method="post",code="200"} 1027 
http_requests_total{method="post",code="400"} 3

使用官方 go 客戶端提供此類指標將確保其有效性

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM