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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

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

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

Go
米琪卡哇伊 2022-06-06 14:47:20
我有一個(gè)將溫度測(cè)量值公開為以下格式的 JSON 的設(shè)備:[  {    "dataPointId": 123456,    "values": [      {        "t": 1589236277000,        "v": 14.999993896484398      },      {        "t": 1589236877000,        "v": 14.700006103515648      },      {        "t": 1589237477000,        "v": 14.999993896484398      },[..]如您所見,這些值包含時(shí)間戳和溫度測(cè)量值。我想通過(guò) Prometheus 指標(biāo)公開這些測(cè)量結(jié)果,所以我正在使用prometheus/client_golang它來(lái)構(gòu)建一個(gè)導(dǎo)出器。我的期望是/metrics端點(diǎn)然后從上面的數(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我實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的prometheus.Collector,我正在添加我的靜態(tài)指標(biāo),沒有任何問(wèn)題。對(duì)于上面的測(cè)量,NewMetricWithTimestamp似乎是添加帶有時(shí)間戳的指標(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))}但是,這會(huì)導(dǎo)致以下我不完全理解的錯(cuò)誤: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)簽組合必須是唯一的,但由于我還添加了時(shí)間戳,這不算作唯一指標(biāo)嗎?我的期望甚至可能嗎?如何在 Prometheus 導(dǎo)出器中表示這些測(cè)量值?
查看完整描述

2 回答

?
aluckdog

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ì)您有所幫助。


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

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


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

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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