2 回答

TA貢獻1847條經驗 獲得超7個贊
來自普羅米修斯的參考
A gauge is a metric that represents a single numerical value that can arbitrarily go up and down. A histogram samples observations (usually things like request durations or response sizes) and counts them in configurable buckets.
Gauge
用于我們關心的一個值,不關心時間戳。像當前溫度,而不是前一天的溫度。
Gauge
不是您要查找的指標類型。或者,prometheus 可能不是您想要的。
當我們想要監控溫度時,我們使用histogram
. 您可以在短時間內計算平均溫度、最低溫度或最高溫度。但是,當你想使用自己的時間戳時,你需要自己實現一個直方圖收集器。您可以從prometheus/client_golang/histogram.go檢查文件。一點都不簡單。
你真正需要的是 A time series database
,比如 influxdb。您可以將數據推送到接受自定義時間戳的 influxdb 中,就像將 json 發布到 http 一樣簡單,然后使用grafana
.
希望對您有所幫助。

TA貢獻2016條經驗 獲得超9個贊
如果仔細觀察,您會發現 JSON 數據格式在度量收集的上下文中略有冗余,因為時間戳在每個設備內部,而不是作為父鍵并且具有作為設備 ID 和值數組的值。只有這樣你才能循環實時序列數據,然后你的標簽不會像現在一樣在循環中是靜態的。標簽唯一性是標簽名稱 + 標簽值散列在一起。
我認為首選的方法是制作一個量規向量。用于WithLabelValues獲取Gauge對象并調用Set它來設置值
deviceTempGaugeVector := prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "my_temperature_celsius",
},
[]string{
"device_id" // Using single label instead of 2 labels "id" and "value"
},
)
prometheus.MustRegister(deviceTempGaugeVector)
for _, point := range dp.TimeStamps {
for _, measurements := range point {
deviceId := measurements.DatapointID
value := measurements.V
metric := deviceTempGaugeVector.WithLabelValues(deviceId).Set(value)
ch <- prometheus.NewMetricWithTimestamp(time.Unix(measurements.T, 0),metric)
}
}
參考:https ://godoc.org/github.com/prometheus/client_golang/prometheus#NewGaugeVec
- 2 回答
- 0 關注
- 432 瀏覽
添加回答
舉報