Logparser Input Plugin

发布时间:2026/9/13 18:35:51
Logparser Input Plugin Logparser Input Plugin【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegrafDeprecated in 1.10: Please use the tail plugin along with thegrok[data format][].tsd-001 规范还给出了更严格包含移除版本的写法 text **Deprecated in version v1.15.0 and scheduled for removal in v1.35.0**: Please use the [tail][] plugin with the [grok data format][grok parser] instead!仓库中可直接参阅 plugins/inputs/tail/README.md 与 docs/DATA_FORMATS_INPUT.md 作为替代方案文档。4.3 自动警告与配置检测一旦登记Telegraf 会在配置加载阶段自动检测被弃用插件并打印警告无需插件自身任何代码配合2022-01-26T20:08:15Z W! DeprecationWarning: Plugin inputs.logparser deprecated since version 1.15.0 and will be removed in 2.0.0: use inputs.tail with grok data format instead从源码结构看这一检测由 config/deprecation.go 的collectDeprecationInfo()完成它依据 categoryinputs/outputs/processors/aggregators查询对应Deprecations映射表通过determineEscalation()计算级别并在printUserDeprecation()中——若级别已为Error——直接返回errors.New(plugin deprecated)使配置校验失败。五、弃用插件选项Deprecate options完整操作5.1 两步走改配置示例 加结构体 tag第一步在 sample config 中把该选项注释掉并标注弃用版本与替代项## Broker to publish to. ## deprecated in 1.7; use the brokers option # url amqp://localhost:5672/influxdb第二步在插件配置结构体中为字段添加deprecatedtagtype AMQP struct { URL string toml:url deprecated:1.7.0;use brokers instead Precision string toml:precision deprecated:1.2.0;option is ignored }deprecatedtag 的格式为since version[;removal version];notice即第一段since版本必填第二段removal版本可选缺省时按上一章规则默认下个大版本第三段notice提示注意源码中的解析逻辑是strings.SplitN(tag, ;, 3)后取最后一段为Notice因此即使只有两段也能正确工作。5.2 仓库中的真实示例仓库中有大量实际应用的deprecatedtag可作写代码时的参照plugins/common/mqtt/mqtt.goclient_trace→deprecated:1.37.0;1.45.0;use log_level trace instead完整三段式plugins/inputs/activemq/activemq.goserver/port→deprecated:1.11.0;use url instead两段式plugins/inputs/http_response/http_response.gobearer_token→deprecated:1.39.0;1.45.0;use token insteadplugins/inputs/mock/mock.gomin/max→ 重命名为start/stepplugins/inputs/openweathermap/openweathermap.goquery_style→option is ignored due to upstream API change上游 API 变化导致的纯忽略型弃用。5.3 自动检测与运行时提示选项一旦带 tag只要该字段在配置中被设置value.IsZero()为 false 才会被收集Telegraf 自动输出2022-01-26T20:08:15Z W! DeprecationWarning: Option url of plugin outputs.amqp deprecated since version 1.7.0 and will be removed in 2.0.0: use brokers instead关键实现细节在collectDeprecationInfo()它通过walkPluginStruct()对插件结构体做DFS 深度优先遍历reflect反射实现能够递归进入嵌套 struct、slice/array 与 map 元素找出所有带deprecatedtag 的字段随后将 toml 字段名作为展示名。当选项级别为Error时printUserDeprecation()会汇总所有已到期选项并以plugin options %q deprecated报错。六、弃用选项值Deprecate option value完整操作某些场景下被弃用的不是整个选项而是某个特定取值如mode old。由于 tag 机制无法表达值粒度需要手动处理从sample.conf中移除该值的示例在插件Init()方法中当检测到该值确实被使用时调用PrintOptionValueDeprecationNoticefunc (e *Example) Init() error { ... if e.Mode old { models.PrintOptionDeprecationNotice(telegraf.Warn, inputs.example, mode, telegraf.DeprecationInfo{ Since: 1.23.1, RemovalIn: 1.40.0, Notice: use v1 instead, }) } ... return nil }实际实现中该打印函数位于 config/deprecation.go 的PrintOptionValueDeprecationNotice其签名接收plugin、option、被使用的value任意类型与DeprecationInfo输出示例W! DeprecationWarning: Value old for option mode of plugin inputs.example deprecated since version 1.23.1 and will be removed in 1.40.0: use v1 instead测试用例 config/deprecation_test.go 中的TestPluginOptionValueDeprecation覆盖了字符串、nil、布尔、整数等多种 value 类型的输出断言验证了%v格式化下的稳定表现。之所以放在Init()中手动触发是因为只有插件运行时才知道实际传入的取值——这是比字段是否被设置更精细的一层判断。七、弃用指标Deprecate metrics当某个指标字段/tag/measurement需要被弃用时例如system插件输出的uptime_format字段被uptime取代第一步在插件 README 的指标列表中标注弃用并指明替代- system - fields: - uptime_format (string, deprecated in 1.10: use uptime field)第二步在 sample config 中给出注释掉的过滤配置方便用户一键启用、剔除旧指标[[inputs.system]] ## Uncomment to remove deprecated metrics. # fieldexclude [uptime_format]这种做法的优点在于移除动作由用户自行完成通过fieldexclude/tagexclude等通用过滤机制Telegraf 核心无需为旧指标保留任何解析逻辑也不产生运行时报错——指标层面的弃用是纯文档 配置引导式的。八、警告的收集、展示与升级源码级原理8.1 启动时的汇总检查Config.printUserDeprecation(category, name, plugin)在每次插件实例化配置时被调用完成三件事检查整个插件是否弃用并打印遍历结构体收集所有被设置的弃用选项并逐个打印若插件或任一选项已达移除版本logLevel telegraf.Error返回错误终止配置解析。8.2 全量清单命令Config.CollectDeprecationInfos()会遍历inputs/outputs/processors/aggregators四个注册表的所有插件支持按名字过滤PrintDeprecationList()则输出全局弃用清单——这也是telegraf config类命令展示弃用状态的基础。输出按名称排序形如inputs.aerospike warn since 1.30.0 removal in 1.40.0 use inputs.prometheus with the Aerospike Prometheus Exporter instead outputs.amon warn since 1.37.0 removal in 1.40.0 service doesnt exist anymore and platform code is unmaintained其中warn/error级别同样由determineEscalation()依据当前版本动态计算。8.3 计数与可观测性incrementPluginDeprecations与incrementPluginOptionDeprecations会分别累计弃用插件数、弃用选项数存入Config.Deprecations映射供上层如自监控统计当前配置的弃用健康度。8.4 测试保障config/deprecation_test.go 通过替换telegrafVersion为伪造版本如1.30.0来模拟不同时间点并切换log.Writer()到缓冲区断言输出文本覆盖了插件弃用的Error/Warn/None三级别输出TestPluginDeprecation选项弃用含/不含 removal 版本时的行为TestPluginOptionDeprecation选项值弃用多种 value 类型输出TestPluginOptionValueDeprecation。这套测试模式证明弃用提示的级别完全由版本号驱动且输出格式可精确断言为维护者修改版本号提供了安全网。九、移除代码Removal的完整流程弃用只是第一步最终目标是在RemovalIn版本真正移除。流程如下等待目标版本弃用 PR 合并并发布后等待到达RemovalIn对应的版本在发布节奏上需先完成所有排期内的 bugfix 版本直到RemovalIn成为下一个正式版本提交移除 PR删除插件/选项/选项值的代码以及所有引用具体包括插件源码、该分类下的all注册文件如 plugins/inputs/all相关的测试用例含其他插件引用的测试数据README 及各类文档中的引用保留弃用条目即使代码已删除必须保留deprecations.go中的弃用信息——这样从远古版本升级而来的用户在报错信息中仍能看到该插件曾在何时弃用、为什么弃用printHistoricPluginDeprecationNotice专门负责输出这类历史提示E! DeprecationError: Plugin inputs.logparser deprecated since version 1.15.0 and removed: use inputs.tail with grok data format instead【免费下载链接】telegrafAgent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.项目地址: https://gitcode.com/GitHub_Trending/te/telegraf创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考