Telegraf json_v2语法分析器错误:无法将字段转换为类型int.strconv.ParseInt:正在分析无



您好!

我制作了一个小型物联网设备,使用ESP32和几个传感器监测特定外壳内的情况。我想通过将数据发布到ThingSpeak云来监控这些数据,然后用Telegraf将其写入InfluxDB,最后使用Grafana中的InfluxDB数据源将其可视化。

到目前为止,除了一个小的例外,我已经让一切完美无瑕。这就是:我的telegrap配置中的一个插件失败,错误为:

分析度量失败:无法将字段"temperature"转换为类型int:strconv。ParseInt:解析";15.4〃:无效语法

插件是[inputs.http]][[inputs.http.json_v2]],我对它们所做的是根据我的ThingSpeak API进行身份验证并解析字段的json输出。然后,在[[inputs.http.json_v2.field]]下的/etc/telegraf/telegraf.conf中,我添加了type = int,否则Telegraph会将我的度量写入InfluxDB中的Strings,而可视化它们的唯一方法是使用一个表或一个stat,因为其余的流量查询都会失败,并出现错误unsupported input type for mean aggregate: string。然而,当我在配置文件中更改为type = float时,我会得到一个不同的错误:

不可处理的实体:向数据库写入点失败:部分写入:字段类型冲突:输入字段"温度";"关于测量";sensorData";是类型float,已作为类型字符串存在,丢弃=1

我怀疑我错误地配置了解析器插件,但经过数小时的调试,我无法找到解决方案。

一些可能有用的信息:Telegraf版本:Telegraf 1.24.2Influxdb版本:InfluxDB v2.4.0请参阅下面的telegraf.conf以及错误消息。

如有任何帮助,我们将不胜感激!(:

[agent]
interval = "10s"
round_interval = true
metric_batch_size = 1000
metric_buffer_limit = 1000
collection_jitter = "0s"
flush_interval = "10s"
flush_jitter = "0s"
precision = ""
hostname = ""
omit_hostname = false
[[outputs.influxdb_v2]]
urls = ["http://localhost:8086"]
token = "XXXXXXXX"
organization = "XXXXXXXXX"
bucket = "sensor"
[[inputs.http]]
urls = [
"https://api.thingspeak.com/channels/XXXXX/feeds.json?api_key=XXXXXXXXXX&results=2"
]
name_override = "sensorData"
tagexclude = ["url", "host"]
data_format = "json_v2"
## HTTP method
method = "GET"
[[inputs.http.json_v2]]
[[inputs.http.json_v2.field]]
path = "feeds.1.field1"
rename = "temperature"
type = "int"        #Error message 1 
#type = "float"     #Error message 2

当类型="时出错;float":

me@myserver:/etc/telegraf$ telegraf -config telegraf.conf --debug
2022-10-16T00:31:43Z I! Starting Telegraf 1.24.2
2022-10-16T00:31:43Z I! Available plugins: 222 inputs, 9 aggregators, 26 processors, 20 
parsers, 57 outputs
2022-10-16T00:31:43Z I! Loaded inputs: http
2022-10-16T00:31:43Z I! Loaded aggregators:
2022-10-16T00:31:43Z I! Loaded processors:
2022-10-16T00:31:43Z I! Loaded outputs: influxdb_v2
2022-10-16T00:31:43Z I! Tags enabled: host=myserver
2022-10-16T00:31:43Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"myserver", 
Flush Interval:10s
2022-10-16T00:31:43Z D! [agent] Initializing plugins
2022-10-16T00:31:43Z D! [agent] Connecting outputs
2022-10-16T00:31:43Z D! [agent] Attempting connection to [outputs.influxdb_v2]
2022-10-16T00:31:43Z D! [agent] Successfully connected to outputs.influxdb_v2
2022-10-16T00:31:43Z D! [agent] Starting service inputs
2022-10-16T00:31:53Z E! [outputs.influxdb_v2] Failed to write metric to sensor (will be 
dropped: 422 Unprocessable Entity): unprocessable entity: failure writing points to 
database: partial write: field type conflict: input field "temperature" on measurement 
"sensorData" is type float, already exists as type string dropped=1
2022-10-16T00:31:53Z D! [outputs.influxdb_v2] Wrote batch of 1 metrics in 8.9558ms
2022-10-16T00:31:53Z D! [outputs.influxdb_v2] Buffer fullness: 0 / 10000 metrics

当类型="时出错;int";

me@myserver:/etc/telegraf$ telegraf -config telegraf.conf --debug
2022-10-16T00:37:05Z I! Starting Telegraf 1.24.2
2022-10-16T00:37:05Z I! Available plugins: 222 inputs, 9 aggregators, 26 processors, 20 
parsers, 57 outputs
2022-10-16T00:37:05Z I! Loaded inputs: http
2022-10-16T00:37:05Z I! Loaded aggregators:
2022-10-16T00:37:05Z I! Loaded processors:
2022-10-16T00:37:05Z I! Loaded outputs: influxdb_v2
2022-10-16T00:37:05Z I! Tags enabled: host=myserver
2022-10-16T00:37:05Z I! [agent] Config: Interval:10s, Quiet:false, Hostname:"myserver", 
Flush Interval:10s
2022-10-16T00:37:05Z D! [agent] Initializing plugins
2022-10-16T00:37:05Z D! [agent] Connecting outputs
2022-10-16T00:37:05Z D! [agent] Attempting connection to [outputs.influxdb_v2]
2022-10-16T00:37:05Z D! [agent] Successfully connected to outputs.influxdb_v2
2022-10-16T00:37:05Z D! [agent] Starting service inputs
2022-10-16T00:37:10Z E! [inputs.http] Error in plugin: 
[url=https://api.thingspeak.com/channels/XXXXXX/feeds.json? 
api_key=XXXXXXX&results=2]: parsing metrics failed: Unable to convert field 
'temperature' to type int: strconv.ParseInt: parsing "15.3": invalid syntax

通过将type = float留在telegraf.conf中的[[inputs.http.json_v2.field]]下,并在Influx中使用新的API键创建NEW存储桶来修复此问题。

问题是,我之前在telegraf.conf中定义的bucketsensor已经在我的流入数据库中创建了字段温度,该字段温度的类型设置为last(又名:String(,不能用新类型mean(别名:float(覆盖。

一旦我删除了所有预先存在的bucket,一切都开始按预期工作。

InfluxDB仪表板

最新更新