3 回答

TA貢獻1828條經驗 獲得超4個贊
好吧,這個話題已經很老了,但以防萬一其他人不得不處理它。以下代碼適用于當前代碼庫v0.9.0-pre1
// [...] imports, metric initialization ...
func main() {
// go get rid of any additional metrics
// we have to expose our metrics with a custom registry
r := prometheus.NewRegistry()
r.MustRegister(myMetrics)
handler := promhttp.HandlerFor(r, promhttp.HandlerOpts{})
// [...] update metrics within a goroutine
http.Handle("/metrics", handler)
log.Fatal(http.ListenAndServe(":12345", nil))
}

TA貢獻1795條經驗 獲得超7個贊
這在 Go 客戶端中目前是不可能的,一旦https://github.com/prometheus/client_golang/issues/46完成,您將有辦法做到這一點。
一般來說,您希望您的自定義導出器導出這些,我知道目前沒有意義的唯一導出器是 snmp 和 blackbox 導出器。
順便說一句,timestamp
作為標簽似乎很奇怪,如果你想要的話,你可能應該使用日志記錄而不是指標。請參閱https://blog.raintank.io/logs-and-metrics-and-graphs-oh-my/ 普羅米修斯的方式是將時間戳作為一個值,而不是一個標簽。

TA貢獻1946條經驗 獲得超3個贊
- 3 回答
- 0 關注
- 529 瀏覽
添加回答
舉報