普罗米修斯收集器失败,收集的指标以前使用相同的名称和标签值&Quot;收集 [英] Prometheus Collector fails with "collected metric was collected before with the same name and label values"
本文介绍了普罗米修斯收集器失败,收集的指标以前使用相同的名称和标签值&Quot;收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个设备,它将温度测量结果显示为以下格式的JSON:
[
{
"dataPointId": 123456,
"values": [
{
"t": 1589236277000,
"v": 14.999993896484398
},
{
"t": 1589236877000,
"v": 14.700006103515648
},
{
"t": 1589237477000,
"v": 14.999993896484398
},
[..]
如您所见,这些值同时包含时间戳和温度测量值。我想通过普罗米修斯指标公开这些度量,因此我使用prometheus/client_golang
构建一个导出器。
我的预期是/metrics
终结点随后会从上面的数据中公开类似以下内容:
# HELP my_temperature_celsius Temperature
# TYPE my_temperature_celsius gauge
my_temperature_celsius{id="123456"} 14.999993896484398 1589236277000
my_temperature_celsius{id="123456"} 14.700006103515648 1589236877000
my_temperature_celsius{id="123456"} 14.999993896484398 1589237477000
我实现了一个简单的prometheus.Collector
,我正在添加我的静态指标,没有任何问题。对于上面的测量,NewMetricWithTimestamp
似乎是添加带有时间戳的指标的唯一方法,所以我使用如下内容迭代这些值:
for _, measurements := range dp.Values {
ch <- prometheus.NewMetricWithTimestamp(
time.Unix(measurements.T, 0),
prometheus.MustNewConstMetric(
collector.temperature,
prometheus.GaugeValue,
float64(measurements.V),
device.DatapointID))
}
但是,这会导致我不完全理解的以下错误:
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
[..]
我知道指标和标签组合必须是唯一的,但由于我还添加了时间戳,这不算唯一指标吗?我的期望值有可能超过吗?
如何在普罗米修斯导出器中表示这些测量值?
推荐答案
引用自Prometheus
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
不是您要查找的指标类型。或者,普罗米修斯可能不是你要找的东西。
当我们想要监控温度时,我们使用histogram
。它可以在短时间内计算出平均温度、最低温度或最高温度。但是,当您想要使用自己的时间戳时,您需要自己实现一个直方图收集器。您可以从prometheus/client_golang/histogram.go查看该文件。一点都不简单。
time series database
,如impxdb。您可以将数据放入接受定制时间戳inumxdb中,就像将json发送到http一样简单,然后使用grafana
监视数据。
希望这对您有帮助。
这篇关于普罗米修斯收集器失败,收集的指标以前使用相同的名称和标签值&Quot;收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文