日安!
我已经建立了一个小型IoT设备,它使用ESP32和几个传感器监视特定外壳内的情况。我希望通过将数据发布到ThingSpeak云中,然后用Telegraf将其写入InfluxDB,最后使用Grafana中的InfluxDB数据源将其可视化,从而监视这些数据。
到目前为止,我已经让一切都完美无缺,但有一个小例外。这是:我的telegraf配置中的一个插件失败了,错误是:
解析度量失败:无法将字段“温度”转换为int: strconv.ParseInt:解析"15.4":无效语法
插件是[inputs.http]]
和[[inputs.http.json_v2]]
,我用它们所做的是根据我的ThingSpeak API进行身份验证,并解析字段的json
输出。然后,在我的/etc/telegraf/telegraf.conf
in [[inputs.http.json_v2.field]]
中,我添加了type = int
,否则telegraf将我的指标写成InfluxDB中的String,而可视化它们的唯一方法是使用一个表或一个stat,因为其他的流量查询都会因为错误unsupported input type for mean aggregate: string
而失败。但是,当我在配置文件中更改为type = float
时,会得到一个不同的错误:
非处理实体:失败写入指向数据库:部分写入:字段类型冲突:测量"sensorData“上的输入字段”温度“是类型浮点数,已以字符串dropped=1的形式存在。
我怀疑我错误地配置了解析器插件,但是经过几个小时的调试,我无法找到解决方案。
一些可能有用的信息: Telegraf版本:Telegraf 1.24.2
Influxdb版本: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
发布于 2022-10-17 21:46:14
修正方法是将type = float
保留在[[inputs.http.json_v2.field]]
下的telegraf.conf
中,并创建一个新的桶,并在流入中使用新的API键。
问题是,我以前在telegraf.conf
中定义的存储桶telegraf.conf
已经在以前的尝试中在流入数据库中创建了字段温度,其类型设置为last
(又名:String
),不能用新类型mean
(又名:float
)覆盖。
一旦我删除了所有预先存在的桶,一切都开始正常工作。
https://stackoverflow.com/questions/74083933
复制相似问题