2 回答
TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超7個(gè)贊
來(lái)自普羅米修斯的參考
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用于我們關(guān)心的一個(gè)值,不關(guān)心時(shí)間戳。像當(dāng)前溫度,而不是前一天的溫度。
Gauge不是您要查找的指標(biāo)類型?;蛘撸琾rometheus 可能不是您想要的。
當(dāng)我們想要監(jiān)控溫度時(shí),我們使用histogram. 您可以在短時(shí)間內(nèi)計(jì)算平均溫度、最低溫度或最高溫度。但是,當(dāng)你想使用自己的時(shí)間戳?xí)r,你需要自己實(shí)現(xiàn)一個(gè)直方圖收集器。您可以從prometheus/client_golang/histogram.go檢查文件。一點(diǎn)都不簡(jiǎn)單。
你真正需要的是 A time series database,比如 influxdb。您可以將數(shù)據(jù)推送到接受自定義時(shí)間戳的 influxdb 中,就像將 json 發(fā)布到 http 一樣簡(jiǎn)單,然后使用grafana.
希望對(duì)您有所幫助。
TA貢獻(xiàn)2016條經(jīng)驗(yàn) 獲得超9個(gè)贊
如果仔細(xì)觀察,您會(huì)發(fā)現(xiàn) JSON 數(shù)據(jù)格式在度量收集的上下文中略有冗余,因?yàn)闀r(shí)間戳在每個(gè)設(shè)備內(nèi)部,而不是作為父鍵并且具有作為設(shè)備 ID 和值數(shù)組的值。只有這樣你才能循環(huán)實(shí)時(shí)序列數(shù)據(jù),然后你的標(biāo)簽不會(huì)像現(xiàn)在一樣在循環(huán)中是靜態(tài)的。標(biāo)簽唯一性是標(biāo)簽名稱 + 標(biāo)簽值散列在一起。
我認(rèn)為首選的方法是制作一個(gè)量規(guī)向量。用于WithLabelValues獲取Gauge對(duì)象并調(diào)用Set它來(lái)設(shè)置值
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 關(guān)注
- 472 瀏覽
添加回答
舉報(bào)
