“ 本文是 filter_grep 过滤插件的使用示例,同时也演示了测试插件功能的一般性方法。” 【测试环境】 filter_grep 是一个比较纯粹的文本处理插件,不依赖第三方软件。 这类插件是最容易测试的,我们不需要搭建复杂的环境,只需要本地运行一个Fluentd,准备好测试数据,专注于调整插件的配置项就行了。 我的测试环境就搭建在一台安装了 Windows 10 系统的笔记本上。 Fluentd 具体安装和运行方法可以参见:这里。 【配置文件】 这是用到的 td-agent.conf。 <source> @type forward </source>
<filter foo.bar> @type grep <regexp> key message pattern /cool/ </regexp> <regexp> key hostname pattern /^web\d+\.example\.com$/ </regexp> <exclude> key message pattern /uncool/ </exclude> <exclude> key status_code pattern /^5\d\d$/ </exclude> </filter>
<match **> @type stdout </match> input 使用 in_forward,用于接收 fluent-cat 发送来的测试数据; output 使用 out_stdout,可直接将数据输出到 td-agent 命令提示符窗口中。 filter 使用 filter_grep,分别配置了两对<regexp>和<exclude>。 实际上,对于任何一个你想使用的插件,都可以使用这样的配置进行功能验证。 你可以方便的构造和接收测试数据,并观察插件的执行结果。 如果你使用的 output 插件要将数据输出到外部系统,你也可以使用 out_copy 将数据拷贝输出到 stdout,在 Fluentd 本地日志先行查看处理结果,对比本地和外部系统的输出数据,来确定插件行为是否正常。 【测试过程】
【数据分析】
|
|
来自: RealPython > 《Fluentd》