flume_log4j

Log4j2的flume appender配置 由于log4j2比1.x版本的效率据说要高,头疼于日志量太大拖系统资源所以决定试试log4j2,而flume appender就是直接把日志输出到flume agent的方法。 此前使用flume自带的tools——flume-ng-log4jappender,通过在在配置文件中引用其FlumeAppender实现类即可,关于此的文章有很多就不赘述。不过在了解过log4j2后发现,log4j2自带 阅读详情
1.  Log4j Appender
1.1.  使用说明
1.1.2.  Client端Log4j配置文件
(黄色文字为需要配置的内容)
log4j.rootLogger= INFO,A1,R
 
 
# ConsoleAppender out
log4j.appender.A1= org . apache .log4j.ConsoleAppender
log4j.appender.A1.layout= org . apache .log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern= %d{ yyyy /MM/ dd HH : mm:ss}%-5p%-10C {1}   %m%n
# File out
//日志 Appender修改为flume提供的Log4jAppender
log4j.appender.R= org . apache . flume .clients.log4jappender.Log4jAppender
log4j.appender.R.File= ${ catalina .home}/logs/ ultraIDCPServer .log
//日志需要发送到的端口号,该端口要有ARVO类型的source在监听
log4j.appender.R.Port = 44444
//日志需要发送到的主机ip,该主机运行着ARVO类型的source
log4j.appender.R.Hostname = localhost
log4j.appender.R.MaxFileSize= 102400KB
# log4j.appender.R.MaxBackupIndex=5
log4j.appender.R.layout= org . apache .log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern= %d{ yyyy /MM/ dd HH\ : mm \: ss }%-5p%-10C {1}   %m%n
log4j.appender.R.encoding= UTF-8
 
log4j.logger.com.ultrapower.ultracollector.webservice.MessageIntercommunionInterfaceImpl= INFO, webservice
log4j.appender.webservice= org . apache .log4j.FileAppender
log4j.appender.webservice.File= ${ catalina .home}/logs/logsMsgIntercommunionInterface.log
log4j.appender.webservice.layout= org . apache .log4j.PatternLayout
log4j.appender.webservice.layout.ConversionPattern= %d{ yyyy /MM/ dd HH\ : mm \: ss }%-5p[%t]%l%X-%m%n
log4j.appender.webservice.encoding= UTF-8
注:Log4jAppender继承自AppenderSkeleton,没有日志文件达到特定大小,转换到新的文件的功能
1.1.3.  flume agent配置
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1
# Describe/configure source1
agent1.sources.source1.type = avro
agent1.sources.source1.bind = 192.168.0.141
agent1.sources.source1.port = 44444
 
# Describe sink1
agent1.sinks.sink1.type = FILE_ROLL
agent1.sinks.sink1.sink.directory = /home/yubojie/flume/apache-flume-1.2.0/flume-out
 
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100
 
# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
注:生成的文件的规则为每隔固定时间间隔生成一个新的文件,文件里面保存该时间段agent接收到的信息
1.2.  分析
1.       使用简便,工作量小。
2.       用户应用程序使用log4j作为日志记录jar包,而且项目中使用的jar包要在log4j-1.2.15版本以上,
3.       应用系统必须将flume所需jar包引入到项目中。如下所示为所有必须jar包:可能会存在jar冲突,影响应用运行
4.       能够提供可靠的数据传输,使用flume log4jAppender采集日志可以不在客户机上启动进程,而只通过修改logapppender直接把日志信息发送到采集机(参见图一),此种情况可以保证采集机接受到数据之后的数据可靠性,但是客户机与采集机连接失败时候数据会丢失。改进方案是在客户机上启动一个agent,这样可以保证客户机和采集机不能连通时,当能连通是日志也被采集上来,不会发送数据的丢失(参见图二),为了可靠性,需在客户机上启动进程
               
1.3.  日志代码
Log.info(“this message has DEBUG in it”);
1.4.  采集到的数据样例
this message has DEBUG in it
this message has DEBUG in it
 
2.  Exec source(放弃)
The problem with ExecSource and other asynchronous sources is that thesource can not guarantee that if there is a failure to put the event into theChannel the client knows about it. In such cases, the data will be lost. As afor instance, one of the most commonly requested features is the tail -F [file] -like use casewhere an application writes to a log file on disk and Flume tails the file,sending each line as an event. While this is possible, there’s an obviousproblem; what happens if the channel fills up and Flume can’t send an event?Flume has no way of indicating to the application writing the log file that itneeds to retain the log or that the event hasn’t been sent, for some reason. Ifthis doesn’t make sense, you need only know this: Your application can neverguarantee data has been received when using a unidirectional asynchronousinterface such as ExecSource! As an extension of this warning - and to becompletely clear - there is absolutely zero guarantee of event delivery whenusing this source. You have been warned.
注:即使是agent内部的可靠性都不能保证
2.1.  使用说明
2.1.1.  flume agent配置
 
# The configuration file needs to define the sources,
# the channels and the sinks.
# Sources, channels and sinks are defined per agent,
# in this case called 'agent'
# example.conf: A single-node Flume configuration
 
# Name the components on this agent
 
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1
# Describe/configure source1
#agent1.sources.source1.type = avro
agent1.sources.source1.type = exec
agent1.sources.source1.command = tail -f /home/yubojie/logs/ultraIDCPServer.log
#agent1.sources.source1.bind = 192.168.0.146
#agent1.sources.source1.port = 44444
 
agent1.sources.source1.interceptors = a
agent1.sources.source1.interceptors.a.type = org.apache.flume.interceptor.HostInterceptor$Builder
agent1.sources.source1.interceptors.a.preserveExisting = false
agent1.sources.source1.interceptors.a.hostHeader = hostname
 
 
# Describe sink1
#agent1.sinks.sink1.type = FILE_ROLL
#agent1.sinks.sink1.sink.directory = /home/yubojie/flume/apache-flume-1.2.0/flume-out
agent1.sinks.sink1.type = hdfs
agent1.sinks.sink1.hdfs.path = hdfs://localhost:9000/user/
agent1.sinks.sink1.hdfs.fileType = DataStream
 
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100
 
# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
 
2.2.  分析
1.         tail方式采集日志需要宿主主机能够执行tail命令,应该是只有linux系统可以执行,不支持window系统日志采集
2.         EXEC采用异步方式采集,会发生日志丢失,即使在节点内的数据也不能保证数据的完整
3.         tail方式采集需要宿主操作系统支持tail命令,即原始的windows操作系统不支持tail命令采集
2.3.  采集到的数据样例
2012/10/26 02:36:34 INFO  LogTest     this message has DEBUG 中文 in it
2012/10/26 02:40:12 INFO  LogTest     this message has DEBUG 中文 in it
2.4.  日志代码
Log.info(“this message has DEBUG 中文 in it”);
3.  Syslog
Passing messages using syslogprotocol doesn't work well for longer messages.  The syslog appender forLog4j is hardcoded to linewrap around 1024 characters in order to comply withthe RFC.  I got a sample program logging to syslog, picking it up with asyslogUdp source, with a JSON layout (to avoid new-lines in stack traces) onlyto find that anything but the smallest stack trace line-wrapped anyway.  Ican't see a way to reliably reconstruct the stack trace once it is wrapped andsent through the flume chain.( 注:内容不确定是否1.2版本 )
   Syslog TCP需要指定eventsize,默认为2500
   Syslog UDP为不可靠传输,数据传输过程中可能出现丢失数据的情况。
3.1.  使用说明
3.1.1.  Client端示例代码
import  java.io.IOException;
import java.io.OutputStream ;
import  java.net.Socket;
import  java.net.UnknownHostException;
 
 
publicclass  SyslogTcp {
  publicstaticvoid  main(String args[]){
     Socket client =  null ;
      OutputStream  out = null ;
     try  {
       client =  new  Socket( "127.0.0.1" , 5140);
       out= client.getOutputStream(); 
        String event =  "<4>hello\n" ; 
        out.write(event.getBytes()); 
        out.flush(); 
        System. out .println( "发送成功 " );
    }  catch  (UnknownHostException e) {
        // TODO  Auto-generated catch block
       e.printStackTrace();
    }  catch  (IOException e) {
        // TODO  Auto-generated catch block
       e.printStackTrace();
    }  finally {
        try  {
           out.close();
       }  catch  (IOException e) {
            // TODO  Auto-generated catch block
           e.printStackTrace();
       } 
         try  {
           client.close();
       }  catch  (IOException e) {
            // TODO  Auto-generated catch block
           e.printStackTrace();
       }
    }
      
 }
}
 
 
3.1.2.  日志接收的flume agent配置
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1
 
# Describe/configure source1
agent1.sources.source1.type =  syslogtcp
agent1.sources.source1.bind = 127.0.0.1
agent1.sources.source1.port = 5140
 
# Describe sink1
#agent1.sinks.sink1.type =  avro
#agent1.sinks.sink1.channels = channel1
#agent1.sinks.sink1. hostname  = 192.168.0.144
#agent1.sinks.sink1.port = 44444
 
agent1.sinks.sink1.type = FILE_ROLL
agent1.sinks.sink1.sink.directory = E:\\file-out
 
 
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100
 
# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
3.2.     分析
需要编写Client采集代码,增量采集日志信息通过socket发送到flume agent;对于长数据处理不是很理想。可靠性可以参考log4j appender的方式来保证。
 
 
4.  日志过滤 Interceptor( FLUME-1358)
Flume支持依据正则表达式过滤event,但是在1.2.0的源代码中没有发现具体实现的代码,根据FLUME-1358的说明信息,可以将RegexFilteringInterceptor类加入到代码中使用。
需要的操作为:
添加类RegexFilteringInterceptor
修改InterceptorType,添加type与类的映射关系:
REGEX_FILTER(org.apache.flume.interceptor.RegexFilteringInterceptor.Builder.class)
4.1.  Regex FilteringInterceptor说明
This interceptor filters events selectively by interpreting the eventbody as text and matching the text against a configured regular expression. Thesupplied regular expression can be used to include events or exclude events.
Property Name
Default
Description
type
–
The component type name has to be  REGEX_FILTER
regex
”.*”
Regular expression for matching against events
excludeRegex
false
If true, regex determines events to exclude, otherwise regex determines events to include.
4.2.  使用说明(测试配置)
4.2.1.  日志接收的Flume agent配置
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1
 
# Describe/configure source1
agent1.sources.source1.type =  avro
agent1.sources.source1.bind =  localhost
agent1.sources.source1.port = 5140
 
 
agent1.sources.source1. interceptors  = inter1
agent1.sources.source1. interceptors .inter1.type = REGEX_FILTER
agent1.sources.source1. interceptors .inter1. regex  = .*DEBUG.*
agent1.sources.source1. interceptors .inter1.excludeRegex = false
 
 
 
 
# Describe sink1
#agent1.sinks.sink1.type =  avro
#agent1.sinks.sink1.channels = channel1
#agent1.sinks.sink1. hostname  = 192.168.0.144
#agent1.sinks.sink1.port = 44444
 
agent1.sinks.sink1.type = FILE_ROLL
agent1.sinks.sink1.sink.directory = E:\\file-out
 
 
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100
 
# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
5.  HDFS SINK
5.1.  使用说明
输出到hdfs的数据,首先在hdfs上创建文件.tmp,然后文件关闭时,将tmp后缀去掉,存储方案与file输出类似,可以设定时间间隔、文件大小、接受事件条数作为滚动生成新文件的依据,默认30s
 
5.2.  可配置项
Name
Default
Description
channel
–

type
–
The component type name, needs to be  hdfs
hdfs.path
–
HDFS directory path (eg hdfs://namenode/flume/webdata/)
hdfs.filePrefix
FlumeData
Name prefixed to files created by Flume in hdfs directory
hdfs.rollInterval
30
Number of seconds to wait before rolling current file (0 = never roll based on time interval)
hdfs.rollSize
1024
File size to trigger roll, in bytes (0: never roll based on file size)
hdfs.rollCount
10
Number of events written to file before it rolled (0 = never roll based on number of events)
hdfs.batchSize
1
number of events written to file before it flushed to HDFS
hdfs.txnEventMax
100

hdfs.codeC
–
Compression codec. one of following : gzip, bzip2, lzo, snappy
hdfs.fileType
SequenceFile
File format: currently  SequenceFile , DataStream  or CompressedStream (1)DataStream will not compress output file and please don’t set codeC (2)CompressedStream requires set hdfs.codeC with an available codeC
hdfs.maxOpenFiles
5000

hdfs.writeFormat
–
“Text” or “Writable”
hdfs.appendTimeout
1000

hdfs.callTimeout
10000

hdfs.threadsPoolSize
10
Number of threads per HDFS sink for HDFS IO ops (open, write, etc.)
hdfs.rollTimerPoolSize
1
Number of threads per HDFS sink for scheduling timed file rolling
hdfs.kerberosPrincipal
–
Kerberos user principal for accessing secure HDFS
hdfs.kerberosKeytab
–
Kerberos keytab for accessing secure HDFS
hdfs.round
false
Should the timestamp be rounded down (if true, affects all time based escape sequences except %t)
hdfs.roundValue
1
Rounded down to the highest multiple of this (in the unit configured using hdfs.roundUnit ), less than current time.
hdfs.roundUnit
second
The unit of the round down value -  second , minute  or hour .
serializer
TEXT
Other possible options include  AVRO_EVENT  or the fully-qualified class name of an implementation of the EventSerializer.Builder  interface.
serializer.*

 
 
5.3.  Agent配置样例
 
# The configuration file needs to define the sources,
# the channels and the sinks.
# Sources, channels and sinks are defined per agent,
# in this case called 'agent'
# example.conf: A single-node Flume configuration
 
# Name the components on this agent
 
agent1.sources = source1
agent1.sinks = sink1
agent1.channels = channel1
# Describe/configure source1
#agent1.sources.source1.type = avro
agent1.sources.source1.type = exec
agent1.sources.source1.command = tail -f /home/yubojie/logs/ultraIDCPServer.log
#agent1.sources.source1.bind = 192.168.0.146
#agent1.sources.source1.port = 44444
 
agent1.sources.source1.interceptors = a
agent1.sources.source1.interceptors.a.type = org.apache.flume.interceptor.HostInterceptor$Builder
agent1.sources.source1.interceptors.a.preserveExisting = false
agent1.sources.source1.interceptors.a.hostHeader = hostname
 
 
# Describe sink1
#agent1.sinks.sink1.type = FILE_ROLL
#agent1.sinks.sink1.sink.directory = /home/yubojie/flume/apache-flume-1.2.0/flume-out
agent1.sinks.sink1.type = hdfs
agent1.sinks.sink1.hdfs.path = hdfs://192.168.98.20:9000/user/hadoop/yubojietest
agent1.sinks.sink1.hdfs.fileType = DataStream
 
# Use a channel which buffers events in memory
agent1.channels.channel1.type = memory
agent1.channels.channel1.capacity = 1000
agent1.channels.channel1.transactionCapactiy = 100
 
# Bind the source and sink to the channel
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1
 
6.  多agent采集文件到hdfs
6.1.  准备工作
1.         文件采集类打包成jar放到flume/apache-flume-1.2.0/lib目录下
2.         创建fileSourceRecorder.properties空文件放到flume/apache-flume-1.2.0/conf下(将要修改为如果文件不存在则创建该文件,后续将不用再创建这个文件)
 
6.2.  agent配置文件
6.2.1.  agent1
# example.conf: A single-node Flume configuration     
                                                                                                                                                         
# Name the components on this agent                
                                                    
agent1.sources = source1                                                                              
agent1.sinks = sink1                                                                          
agent1.channels = channel1                        
                                                   
# Describe/configure source1                       
agent1.sources.source1.type = com.ultrapower.ultracollector.flume.source.file.FileSource                                                
 
agent1.sources.source1.path = /home/yubojie/logs/ultraIDCPServer.log
#gbk,utf-8 
agent1.sources.source1.encoding = utf-8
agent1.sources.source1.onceMaxReadByte = 999
agent1.sources.source1.cacheQueueSize = 10
agent1.sources.source1.noChangeSleepTime = 1000
agent1.sources.source1.batchCommitSize = 5
agent1.sources.source1.batchWaitTime = 500        
       
#agent1.sources.source1.type = avro
#agent1.sources.source1.bind = localhost
#agent1.sources.source1.port = 44444
                                                                                      
# Describe sink1                                                                                       
#agent1.sinks.sink1.type = logger          
#agent1.sinks.sink1.type = FILE_ROLL
#agent1.sinks.sink1.sink.directory = E:/file-out
#agent1.sinks.sink1.sink.fileName = a.log
agent1.sinks.sink1.type = hdfs
#agent1.sinks.sink1.hdfs.path = hdfs://192.168.98.20:9000/user/hadoop/yubojietest
agent1.sinks.sink1.hdfs.path = hdfs://192.168.0.153:9000/user/file
agent1.sinks.sink1.hdfs.callTimeout = 20000
agent1.sinks.sink1.hdfs.fileType = DataStream
#agent1.sinks.sink1.sink.rollInterval = 30        
               
                                          
# Use a channel which buffers events in memory        
agent1.channels.channel1.type = memory             
agent1.channels.channel1.capacity = 1000           
agent1.channels.channel1.transactionCapactiy = 100 
                                          
                                                  
# Bind the source and sink to the channel                                                              
agent1.sources.source1.channels = channel1
agent1.sinks.sink1.channel = channel1       
    
########################## test method ########################################
 
#########start flume agent ######### 
#agent -n agent1 -f .\conf\flume-conf.properties.template.file.signle
 
######### client send message #########
 
# $ bin/flume-ng avro-client -H localhost -p 44444 -F 'F:/1/log.log'
6.2.2.  agent2
# example.conf: A single-node Flume configuration     
                                                                                                                                                         
# Name the components on this agent                 
                                                   
agent2.sources = source1                                                                              
agent2.sinks = sink1                                                                          
agent2.channels = channel1                        
                                                   
# Describe/configure source1                       
agent2.sources.source1.type = com.ultrapower.ultracollector.flume.source.file.FileSource                                                
 
agent2.sources.source1.path = /home/yubojie/logtest/logs/ultraIDCPServer.log
#gbk,utf-8 
agent2.sources.source1.encoding = utf-8
agent2.sources.source1.onceMaxReadByte = 999
agent2.sources.source1.cacheQueueSize = 10
agent2.sources.source1.noChangeSleepTime = 1000
agent2.sources.source1.batchCommitSize = 5
agent2.sources.source1.batchWaitTime = 500        
       
#agent1.sources.source1.type = avro
#agent1.sources.source1.bind = localhost
#agent1.sources.source1.port = 44444
                                                                                     
# Describe sink1                                                                                        
#agent1.sinks.sink1.type = logger          
#agent1.sinks.sink1.type = FILE_ROLL
#agent1.sinks.sink1.sink.directory = E:/file-out
#agent1.sinks.sink1.sink.fileName = a.log
agent2.sinks.sink1.type = hdfs
#agent1.sinks.sink1.hdfs.path = hdfs://192.168.98.20:9000/user/hadoop/yubojietest
agent2.sinks.sink1.hdfs.path = hdfs://192.168.0.153:9000/user/file
agent2.sinks.sink1.hdfs.callTimeout = 20000
agent2.sinks.sink1.hdfs.fileType = DataStream
#agent1.sinks.sink1.sink.rollInterval = 30        
               
                                          
# Use a channel which buffers events in memory        
agent2.channels.channel1.type = memory             
agent2.channels.channel1.capacity = 1000           
agent2.channels.channel1.transactionCapactiy = 100 
                                          
                                                  
# Bind the source and sink to the channel                                                               
agent2.sources.source1.channels = channel1
agent2.sinks.sink1.channel = channel1       
    
########################## test method ########################################
 
#########start flume agent ######### 
#agent -n agent1 -f .\conf\flume-conf.properties.template.file.signle
 
######### client send message #########
 
# $ bin/flume-ng avro-client -H localhost -p 44444 -F 'F:/1/log.log'
6.3.  启动命令
flume-ng agent -name agent1 -c conf -f ../conf/flume-conf.properties  
//agent1监控/home/yubojie/logs/ultraIDCPServer.log
flume-ng agent -name agent2 -c conf -f ../conf/flume-conf2.properties
//agent2监控/home/yubojie/logtest/logs/ultraIDCPServer.log
6.4.  测试结果
1.         agent1和agent2各自监控相应文件,互不干涉
2.         文件各自输出到hdfs生成各自的文件
6.  参考资料:
资料
RegexFilteringInterceptor源代码
 
 
package org.apache.flume.interceptor;
 
importstatic org.apache.flume.interceptor.RegexFilteringInterceptor.Constants. DEFAULT_EXCLUDE_EVENTS ;
importstatic  org.apache.flume.interceptor.RegexFilteringInterceptor.Constants. DEFAULT_REGEX ;
importstatic  org.apache.flume.interceptor.RegexFilteringInterceptor.Constants. EXCLUDE_EVENTS ;
importstatic  org.apache.flume.interceptor.RegexFilteringInterceptor.Constants. REGEX ;
 
import  java.util.List;
import  java.util.regex.Pattern;
 
import  org.apache.flume.Context;
import  org.apache.flume.Event;
import  org.slf4j.Logger;
import org.slf4j.LoggerFactory ;
 
import  com.google.common.collect.Lists;
 
publicclass  RegexFilteringInterceptor implements  Interceptor {
 
   privatestaticfinal  Logger logger  = LoggerFactory
      . getLogger (RegexFilteringInterceptor. class );
 
   privatefinal  Pattern regex ;
   privatefinalboolean excludeEvents ;
 
   /**
    *Only {@link RegexFilteringInterceptor.Builder} canbuildme
    */
   private  RegexFilteringInterceptor(Pattern regex, boolean  excludeEvents) {
     this . regex  = regex;
     this . excludeEvents  = excludeEvents;
  }
 
  @Override
   publicvoid  initialize() {
     // no- op
  }
 
 
  @Override
   /**
    *Returnstheeventifitpassestheregularexpressionfilterandnull
    *otherwise.
    */
   public  Event intercept(Event event) {
     // We've already ensured here that at most one of includeRegex and
     // excludeRegex are defined.
 
     if  (! excludeEvents ) {
       if  ( regex .matcher( new  String(event.getBody())).find()) {
         return  event;
      }
       else  {
         returnnull ;
      }
    }
     else  {
       if  ( regex .matcher( new  String(event.getBody())).find()) {
         returnnull ;
      }
       else  {
         return  event;
      }
    }
  }
 
   /**
    *Returnsthesetofeventswhichpassfilters,accordingto
    * {@link #intercept(Event)} .
    * @param events
    * @return
    */
  @Override
   public  List<Event> intercept(List<Event> events) {
    List<Event> out = Lists. newArrayList ();
     for  (Event event : events) {
      Event outEvent = intercept(event);
       if  (outEvent != null ) { out.add(outEvent); }
    }
     return  out;
  }
   @Override
   publicvoid  close() {
     // no- op
  }
   /**
    *BuilderwhichbuildsnewinstanceoftheStaticInterceptor.
    */
   publicstaticclass  Builder implements  Interceptor.Builder {
 
     private  Pattern regex ;
     privateboolean excludeEvents ;
     @Override
     publicvoid  configure(Context context) {
      String regexString = context.getString( REGEX , DEFAULT_REGEX );
       regex  = Pattern. compile (regexString);
       excludeEvents  = context.getBoolean( EXCLUDE_EVENTS ,
           DEFAULT_EXCLUDE_EVENTS );
    }
     @Override
     public  Interceptor build() {
       logger .info(String. format (
           "Creating RegexFilteringInterceptor: regex=%s,excludeEvents=%s" ,
           regex , excludeEvents ));
       returnnew  RegexFilteringInterceptor( regex , excludeEvents );
    }
  }
   publicstaticclass  Constants {
     publicstaticfinal  String REGEX  = "regex" ;
     publicstaticfinal  String DEFAULT_REGEX  = ".*" ;
     publicstaticfinal  String EXCLUDE_EVENTS  = "excludeEvents" ;
     publicstaticfinalboolean DEFAULT_EXCLUDE_EVENTS  =  false ;
  }
}
InterceptorType源代码
黄色为添加内容
package org.apache.flume.interceptor;
 
public enum InterceptorType {
 
  TIMESTAMP(org.apache.flume.interceptor.TimestampInterceptor.Builder.class),
  HOST(org.apache.flume.interceptor.HostInterceptor.Builder.class),
   REGEX_FILTER(org.apache.flume.interceptor.RegexFilteringInterceptor.Builder.class) ,
  ;
 
  private final Class<? extends Interceptor.Builder> builderClass;
 
  private InterceptorType(Class<? extends Interceptor.Builder> builderClass) {
    this.builderClass = builderClass;
  }
 
  public Class<? extends Interceptor.Builder> getBuilderClass() {
    return builderClass;
  }
 
}
flume log4j日志接收 flume 安装与配置:下载flume,然后解压:tar xvf apache-flume-1.5.2-bin.tar.gz -C ./配置flume,在conf/flume-conf.properties下(没有则创建,反正有template):# example.conf: A single-node Flume configuration# Name the components on thi 阅读详情

相关推荐

log4j输出日志到flume

log4j输出日志到flume例子,包含log4j配置,flume配置,测试类

flume使用(三):实时log4j日志通过flume输出到MySql数据库

flume使用(一):入门demo flume使用(二):采集远程日志数据到MySql数据库本文在【flume使用(二):...

maoyuanming0806的博客 3173

自动驾驶仿真:Carsim、NI和VTD联合仿真课题二

文章目录前言一、设备配置1、硬件需求2、网络配置二、Carsim工程配置1、创建工程2、创建数据库3、参数配置三、VTD工程配置1、创建工程四、Veristand工程配置1、创建工程五、运行程序 前言 上篇文章《Carsim、NI和VTD联合仿真课题一》简单地介绍了三者之间的联合框架,以及NI与VTD之间简单的组包与拆包指导。这篇文章将要讲述的是如何将三个软件联合起来,如何设置软件参数,用最简单的方法把仿真车开起来。 一、设备配置 1、硬件需求 注:真正的做智能驾驶仿真项目,至少需要两台电脑,一台实时机

zataji的博客 1万+

log4j+flume+kafka实时日志处理

将项目中的日志使用log4j打印,然后使用avro方式,收集到flume,最后输出到kafka。flume官方提供了两种方式接受log4j输入源的方式:Log4J Appender和Load Balancing Log4J Appender,flume详情可查看官网:Welcome to Apache Flume — Apache Flume。 一、appender 1)Log4J Appender参数解释 Property Name Default Descripti......

NDF923的专栏 2404

卷王问卷考试系统——测试报告

本问卷考试系统是一款在线平台,支持用户发布和完成调查问卷,并进行考试管理,核心功能在于简化问卷创建发布、数据收集及考试组织流程。此次测试将围绕其关键模块展开,涵盖用户注册登录、项目列表、我的练习以及我的题库等核心部分。问卷考试系统(一)硬件环境普通办公电脑(CPU:Intel i5 、内存:16GB 、硬盘:512GB )(二)软件环境操作系统:Windows 11 ;浏览器:Chrome(版本 120+)、Firefox(版本 115+)、Edge(版本 120+)验证界面信息在完整性、一致性、准确性和用

m0_73433755的博客 556

STM32入门教程:WiFi通信

STM32是一款强大的嵌入式系统开发平台,可以用于开发各种应用程序,包括WiFi通信。在本教程中,我们将介绍如何使用STM32开发板和WiFi模块进行无线通信。以下是一个详细的代码案例,涵盖了WiFi通信的基本概念和实现。

qq_67153941的博客 1350

flume学习03-flume收集log4j日志

前几篇已经介绍了flume相关的知识,包括flume架构、如何配置启动以及暂停,接下去主要说说flume接受log4j日志。 前面介绍过了log4j需要用avro的方式讲日志传递到flume,所以我们的配置都是基于avro的sourcelog4j日志输出到flume的console 修改配置文件log4j-agent.properties # distributed with this work

Cumu Blog 9078

cadence CIS 库建立--建立自己维护的CIS数据库

遇到一个问题,在使用cadecnce的时候,就是没有自己的本地/分享的数据库。 在画原理图或者PCB的时候,如果能搭建一个自己的数据库,在局域网或者本地 就好了。出于这样的想法,做了一些探索,找到了一种可能的答案。 由于数据库编制知识的缺乏,要自己建一个数据库似乎花费的时间会比较多。 偶发奇想,如果能够改编CIS 自带的数据库 另建立副本进行维护 就能够省下不少麻烦。 先说下CIS 是个啥。网上一搜:总之CIS 是个好东西。 功能强大。 点击CIS capture 中的 Options CIS Config

qq_29776365的博客 2万+

flume入门 log4j 输出日志到flume

将log4j产生的日志直接输出到flume控制台 1.编写客户端 2.pom.xml 3. log4j.properties 4.配置flume 建立testlog2flume.conf 5.到flume目录下启动flume

poorCoder_的博客 7672

时空智友企业流程化管控系统文件上传漏洞

时空智友企业流程化管控系统是一个功能丰富、灵活可定制的企业管理工具。通过该系统,企业能够实现流程的自动化、协同的提升、数据的洞察和决策的优化,从而提高工作效率、管理水平和企业竞争力。时空智友企业流程化管控系统 formservice接口处存在任意文件上传漏洞,未经认证的攻击者可通过此接口上传后门文件,最终可导致服务器失陷。

holyxp的博客 1036

【银河麒麟服务器操作系统】安装英伟达4090D显卡驱动操作指南

本文详细介绍了在银河麒麟高级服务器操作系统V10SP3-2403-X86版本上安装NVIDIA RTX4090D显卡驱动的完整流程。主要内容包括:准备工作检查、开源驱动禁用、运行级别切换、依赖包安装以及交互式安装过程中的关键选项选择(32位库选Yes、X配置选No)。通过禁用nouveau驱动、重建内核引导等步骤确保驱动安装成功,最后通过nvidia-smi命令验证驱动安装情况。文档提供了操作检查表和安装流程图,帮助用户在银河麒麟系统上顺利完成显卡驱动部署。

信创运维工程师 · 银河麒麟 & 容器实战 | 金融生产环境迁移·等保加固 | 142篇原创·17万+阅读 3109

使用Log4j将日志实时写入Flume

需求:使用Flume实时收集WebServer或者其它服务器上通过log4j产生的日志 Agent选型:Log4jAppender的使用 创建一个maven项目,pom.xml文件中引入依赖 dependency> groupId>log4jgroupId> artifactId>log4jartifactId> version>1.2.16version> depe

harvey的博客 3556

华为OD机试双机位C卷-字符串解密(Py/Java/C/C++/Js/Go)

华为OD机试(机考)双机位C卷 【字符串解密】,提供C语言、Java、C++、Python、Go、JavaScript源码实现,并提供完整思路讲解,以及在线OJ模拟做题。华为OD机试 - 字符串解密。

qq_45776114的博客 735

Flume整合log4j和Kafka

log4j配置 配置文件 修改log4j.properties # 设置要进行数据跟踪程序所在的名称 log4j.logger.cn.mldn.myflume=INFO ,flume log4j.appender.flume=org.apache.flume.clients.log4jappender.Log4jAppender log4j.appender.flume.layout...

lql_h的博客 315

2025年06月中国电子学会青少年软件编程(Python)等级考试试卷(二级)答案 + 解析

2025年06月中国电子学会青少年软件编程(Python)等级考试试卷(二级)答案 + 解析

伶俐角少儿编程 460

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

log4j产生日志到flume及log4j为何无法产生日志到flume

log4j产生日志到flume,log4j无法产生日志到flume

WGBLW的博客 1356

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Log4J日志输出到flume中

1:添加依赖 <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.7.25</version> </dependency> <dependency> ...

qq_19248335的博客 290

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

使用log4j将数据流入flume

说说使用log4j将日志流入flume的实现方法及具体配置。

upupfeng的博客 411

flume log4j

log4j 发送日志到 flume 梳理

我叫孙悟空的随笔 487

log4j+flume+HDFS实现日志存储

log4j  日志生成flume  日志收集系统,收集日志,使用版本apache-flume-1.6.0-bin.tar.gz .HDFS  Hadoop分布式文件系统,存储日志,使用版本hadoop-3.0.0-alpha1.tar.gz 部署在同一台虚拟机,虚拟机IP:10.34.11.65,hosts配置如下: HDFS配置 hadoop安装配置 hado

sum__mer的专栏 5641

Log4j写入日志到Flume

一、log4j配置 依赖包引入 <dependency> <groupId>org.apache.flume.flume-ng-clients</groupId> <artifactId>flume-ng-log4jappender</artifactId> <version>1...

Arkham的专栏 757

log4j+flume+hdfs

log4j+flume+hdfs日志简单采集存储 ​ flume+hdfs这篇博客有说 一.Flume配置文件 1.在flume目录下的test文件中,创建配置文件 vim logdemo.conf 内容为 a1.sources=source1 a1.channels=channel1 a1.sinks=sink1 a1.sources.source1.type=avro a1.sources.source1.bind=0.0.0.0 a1.sources.source1.port=44444 a1.s

Joker_Jiang3的博客 320

Log4j整合Flume

1.环境 CDH 5.16.1 Spark 2.3.0 cloudera4 Kafka 2.1.0+kafka4.0.0 2.Log4j——>Flume 2.1 Log4j 产生日志 import org.apache.log4j.Logger; /** * @ClassName LoggerGenerator * @Author wuning * @Date: 2020/2/3 ...

wn147258369的博客 86

Flume-ng在windows环境搭建并测试+log4j日志通过Flume输出到HDFS

首先,去Flume官网下载最新的版本 这里我使用的是apache-flume-1.6.0-bin.tar.gz 开发环境 系统:window7 Jdk:1.7 Flume:1.6.0 Hadoop:2.5.2 一、下载flume并解压安装配置 下载解压到你想要的目录 配置环境变量 新建FLUME_HOME变量,填写flume安装目录,如图 然后编辑系统变

码蚁君 5129

log4j与flume整合配置

通过flume搭建日志服务器,将各系统日志进行集中管理,以便我们对日志进行系统分析来优化系统缺陷、生成报表、推荐等高级功能。

Yashon 5331
上一篇: flume简单配置
下一篇: hive安装配置详解
Java_Soldier
博客等级 码龄10年 27粉丝 82原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值