第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Prometheus 收集器失敗并顯示“之前收集的指標(biāo)具有相同的名稱和標(biāo)簽值”

Prometheus 收集器失敗并顯示“之前收集的指標(biāo)具有相同的名稱和標(biāo)簽值”

Go
米琪卡哇伊 2022-06-06 14:47:20
我有一個將溫度測量值公開為以下格式的 JSON 的設(shè)備:[  {    "dataPointId": 123456,    "values": [      {        "t": 1589236277000,        "v": 14.999993896484398      },      {        "t": 1589236877000,        "v": 14.700006103515648      },      {        "t": 1589237477000,        "v": 14.999993896484398      },[..]如您所見,這些值包含時間戳和溫度測量值。我想通過 Prometheus 指標(biāo)公開這些測量結(jié)果,所以我正在使用prometheus/client_golang它來構(gòu)建一個導(dǎo)出器。我的期望是/metrics端點然后從上面的數(shù)據(jù)中暴露出類似的東西:# HELP my_temperature_celsius Temperature# TYPE my_temperature_celsius gaugemy_temperature_celsius{id="123456"} 14.999993896484398 1589236277000my_temperature_celsius{id="123456"} 14.700006103515648 1589236877000my_temperature_celsius{id="123456"} 14.999993896484398 1589237477000我實現(xiàn)了一個簡單的prometheus.Collector,我正在添加我的靜態(tài)指標(biāo),沒有任何問題。對于上面的測量,NewMetricWithTimestamp似乎是添加帶有時間戳的指標(biāo)的唯一方法,所以我使用這樣的方法迭代這些值:for _, measurements := range dp.Values {  ch <- prometheus.NewMetricWithTimestamp(    time.Unix(measurements.T, 0),    prometheus.MustNewConstMetric(      collector.temperature,      prometheus.GaugeValue,      float64(measurements.V),      device.DatapointID))}但是,這會導(dǎo)致以下我不完全理解的錯誤:An error has occurred while serving metrics:1135 error(s) occurred:* collected metric "my_temperature_celsius" { label:<name:"id" value:"123456" > gauge:<value:14.999993896484398 > timestamp_ms:1589236877000000 } was collected before with the same name and label values* collected metric "my_temperature_celsius" { label:<name:"id" value:"123456" > gauge:<value:14.700006103515648 > timestamp_ms:1589237477000000 } was collected before with the same name and label values[..]我了解指標(biāo)和標(biāo)簽組合必須是唯一的,但由于我還添加了時間戳,這不算作唯一指標(biāo)嗎?我的期望甚至可能嗎?如何在 Prometheus 導(dǎo)出器中表示這些測量值?
查看完整描述

2 回答

?
aluckdog

TA貢獻1847條經(jīng)驗 獲得超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用于我們關(guān)心的一個值,不關(guān)心時間戳。像當(dāng)前溫度,而不是前一天的溫度。

Gauge不是您要查找的指標(biāo)類型?;蛘撸琾rometheus 可能不是您想要的。

當(dāng)我們想要監(jiān)控溫度時,我們使用histogram. 您可以在短時間內(nèi)計算平均溫度、最低溫度或最高溫度。但是,當(dāng)你想使用自己的時間戳?xí)r,你需要自己實現(xiàn)一個直方圖收集器。您可以從prometheus/client_golang/histogram.go檢查文件。一點都不簡單。

你真正需要的是 A time series database,比如 influxdb。您可以將數(shù)據(jù)推送到接受自定義時間戳的 influxdb 中,就像將 json 發(fā)布到 http 一樣簡單,然后使用grafana.

希望對您有所幫助。


查看完整回答
反對 回復(fù) 2022-06-06
?
慕沐林林

TA貢獻2016條經(jīng)驗 獲得超9個贊

如果仔細(xì)觀察,您會發(fā)現(xiàn) JSON 數(shù)據(jù)格式在度量收集的上下文中略有冗余,因為時間戳在每個設(shè)備內(nèi)部,而不是作為父鍵并且具有作為設(shè)備 ID 和值數(shù)組的值。只有這樣你才能循環(huán)實時序列數(shù)據(jù),然后你的標(biāo)簽不會像現(xiàn)在一樣在循環(huán)中是靜態(tài)的。標(biāo)簽唯一性是標(biāo)簽名稱 + 標(biāo)簽值散列在一起。


我認(rèn)為首選的方法是制作一個量規(guī)向量。用于WithLabelValues獲取Gauge對象并調(diào)用Set它來設(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


查看完整回答
反對 回復(fù) 2022-06-06
  • 2 回答
  • 0 關(guān)注
  • 446 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號