我和telegraf processors.regex有一个间歇性的问题(至少这是我最好的猜测)。
我们正在使用下面的telegraf吐露
[[agent]])inputs.conf
[[inputs.http]]
urls = [
"http://myserver.mycompany.com:8080/some/rest/api",
]
username = "user"
password = "password"
name_override = "monitor"
interval = "600s"
timeout = "3s"
data_format = "json"
json_query = "rows"
json_string_fields = [ "size" ]
tagexclude = ["host"]outputs.conf
[[outputs.influxdb]]
database = "metrics"
urls = ["http://influxdb.mycompany.com:8086"]processors.conf
[[processors.converter]]
[processors.converter.fields]
integer = [ "size" ]
# Process order is VERY important here
# Rename the url tag to target
[[processors.rename]]
[[processors.rename.replace]]
tag = "url"
dest = "target"
# Extract the target name from the url (I know we just renamed it ... weird)
[[processors.regex]]
[[processors.regex.tags]]
key = "url"
pattern='^http://(?P<target>[^:/]+).+'
replacement = "${target}"当我跑步时:
telegraf --config telegraf.conf --config-directory telegraf.d --test --debug --input-filter http我得到了我期望的数据,url已经被正则表达式target所取代。
monitor,target=myserver.mycompany.com size=123456789i 1627647959000000000问题是在我创建的grafana图中,我看到了原始的完整url http://myserver.mycompany.com:8080/some/rest/api,而不是处理过的myserver.mycompany.com。此外,当我运行telegraf测试时,偶尔也会看到target与完整的未处理url一起返回,即
monitor,target=http://myserver.mycompany.com:8080/some/rest/api size=123456789i 1627647959000000000数据是正确的,并且已经处理过了,即json中返回的size字符串总是被转换为int,而url总是被重命名为target。
更奇怪的是,我已经将这个配置(在inputs.http中使用不同的urls,取决于区域)推到了多个服务器上,其中大多数服务器的工作与预期完全相同,只有少数服务器具有这种行为。我已经检查并确保了每个服务器匹配的telegraf的所有版本(1.19.1),并且它们都运行在Centos 7上,我还尝试过清除进水数据库中的数据。
在目标中返回url的少数服务器总是这样做的,即使我在它们上运行telegraf测试时,它们也会显示主机已经被剥离掉了。
关于下一步去哪里找有什么提示吗?
发布于 2021-08-18 14:02:35
我已经找到原因了!
来自telegraf文档。
以下配置参数可用于所有处理器: 顺序:这是处理器执行的顺序。如果没有指定这一点,那么处理器执行顺序将是随机。
就连我的评论也揭示了为什么这是个问题
# Process order is VERY important here
# Rename the url tag to target
# Extract the target name from the url (I know we just renamed it ... weird)是的,这是奇怪的,但这是因为我碰巧在我的测试中保持相同的50:50的机会,但其他顺序是相同的。当按错误的顺序重命名键时,regex就没有什么可处理的了。
解决方案是使用order。
processors.conf
[[processors.converter]]
[processors.converter.fields]
integer = [ "size" ]
# Extract the target name from the url
[[processors.regex]]
order = 1
[[processors.regex.tags]]
key = "url"
pattern='^http://(?P<target>[^:/]+).+'
replacement = "${target}"
# Rename the url tag to target
[[processors.rename]]
order = 2
[[processors.rename.replace]]
tag = "url"
dest = "target"现在,正则表达式总是在重命名之前运行。
https://stackoverflow.com/questions/68591724
复制相似问题