如何在Flume的每个事件的前面添加时间戳? 说我有这个日志,但我也想添加时间戳
127.0.0.1 - frank [10 / Oct / 2000:13:55:36 -0700]“GET /apache_pb.gif HTTP / 1.0”200 2326 2016-05-95 127.0.0.1 - frank [10 / Oct / 2000:13:55:36 -0700]“GET /apache_pb.gif HTTP / 1.0”200 2326
答案 0 :(得分:0)
假设您的意思是在事件正文字节的开头添加一个时间戳,那么就没有预先设定的拦截器来执行您所要求的(搜索和替换拦截器可以' t替换为动态值,如日期)。
但是,编写一个拦截器来为每个事件主体添加当前时间戳前缀应该是非常简单的。
检查现有拦截器的源代码作为示例,编译代码并将jar部署到名为<div class="modal-box" id='override'>
Modal Box
</div>
这里是标准水槽拦截器当前来源的链接:
但基本上你只需要创建一个实现$FLUME_HOME/plugins.d/my-plugins/lib/my-plugin.jar
接口的类,并创建一个Interceptor
实现。
答案 1 :(得分:0)
You can use Flume Interceptors: https://flume.apache.org/FlumeUserGuide.html#flume-interceptors to modify events.
You can write your own classes that achieve the functionality you are looking for or you can use Morphline interceptors, too.
If it's not a requirement that you change the body, you can just use timestamp interceptor to add the timestamp to the headers.
答案 2 :(得分:0)
我通过使用Morphline解决了这个问题,在下面添加了这些函数,其中时间戳被添加到每个水槽事件的开头。
{
addCurrentTime { field : timestamp }
},
{
setValues {
_result = "@{timestamp}|@{message}"
}
},