telegraf - Telegraf 间歇性处理器.regex
问题描述
我的电报出现间歇性问题processors.regex
(至少这是我的最佳猜测)
我们正在使用以下电报配置
- /etc/telegraf
- telegraf.conf(仅配置
[[agent]]
) - 电报
- 输入.conf
- 输出.conf
- 处理器.conf
- telegraf.conf(仅配置
输入.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"]
输出.conf
[[outputs.influxdb]]
database = "metrics"
urls = ["http://influxdb.mycompany.com:8086"]
处理器.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 图中,我看到的是原始完整 urlhttp://myserver.mycompany.com:8080/some/rest/api
而不是处理后的myserver.mycompany.com
. 当我运行电报测试时,我也会看到target
返回完整的未处理网址,即
monitor,target=http://myserver.mycompany.com:8080/some/rest/api size=123456789i 1627647959000000000
数据正确且已处理,即size
json 中返回的字符串始终转换为 int 并url
始终重命名为target
.
更奇怪的是,我已经将此配置(在 input.http 中使用不同的 url,具体取决于区域)推送到了许多服务器,并且它们中的大多数都按预期工作,只有少数具有这种行为。我已经检查并确保每台服务器上的所有 Telegraf 版本都匹配(1.19.1)并且它们都在 Centos 7 上运行。我还尝试从 influxdb 中清除数据。
在目标中返回 url 的少数服务器总是这样做,即使当我对它们运行 telegraf 测试时,它们显示主机已按应有的方式被剥离。
关于下一步看哪里的任何提示?
解决方案
我找到了原因!
来自电报文档。
以下配置参数适用于所有处理器:
order:这是处理器执行的顺序。如果未指定,则处理器执行顺序将是随机的。
甚至我的评论也揭示了为什么这是一个问题
# 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 机会,但另一个顺序同样可能。当顺序错误时,键被重命名并且正则表达式没有任何处理。
解决方案是使用order
.
处理器.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"
现在正则表达式将始终在重命名之前运行。
推荐阅读
- javascript - JSXGraph 加倍显示轴标签
- php - 是否可以在作曲家中验证供应商文件夹的完整性?
- java - Spring Boot JPA 获取表元数据
- tfs - TFS 持续集成/部署版本号
- javascript - 使用时刻时区添加日期但不更新
- php - 为什么 floor() 返回值减 1?
- html - 具有列数属性的 Svg 显示探针
- spring - 将 Spring Boot Actuator 作为依赖项包含在项目中时的 StackOverflowError
- reactjs - 从反应原生的方法定义中返回按钮或自定义组件
- python - 有没有办法对使用开始/结束切片的 2D numpy 数组进行矢量化?