Flume-ng spooldir distributed Log Collection directory monitoring

Source: Internet
Author: User
Tags file copy tmp file

OK, come straight to the dry

In the use of Flume-ng, stepped a lot of pits, now for a moment, I hope you bypass the pit to reach the purpose of skilled use of flume


The first pit: can not correctly decode the file, causing the file can not be correctly renamed, after throwing a bug, all files can not be collected by Flume, is a more serious mistake, caused by Flume using NiO method to read the file, will read the file to UTF-8 encoding read, In the Linux state, the default is to store files according to GBK encoding, so the reading will encounter the character length is not enough, workaround: In the Flume configuration file set the monitoring directory to read the encoding of the file.


Second pit: CP large file throws exception, this is because the copy to Spooldir file can not be modified, workaround, use SCP or CP backup file, and then the file MV into Spooldir. You can also use the suffix regular mate to copy the. tmp file, and wait for the copy to complete, rename is not in the first name.


Second pit to modify the source code:

Can modify the source code to avoid large file upload problem, is to modify the source information:



Here are the source code methods that need to be modified:


/** * * @Title: Checkfilecpisover * @Description: Used to check if file copy completed * @param @param currentfile settings file * @ return void returns type * @throws */private void Checkfilecpisover (file file) {Logger.info ("Checkfilecpiso        Ver start ..... "); Long modified = file.lastmodified ();//Current file modification time long length = File.length ();//Current file size try {Threa        D.sleep (1000);//wait 1 seconds} catch (Interruptedexception e) {e.printstacktrace ();        } File Currentfile = new file (File.getabsolutepath ()); int count = 0;//records the number of cycles, more than 20 times, which is 10 seconds after the exception is thrown while (currentfile.lastmodified ()! = Modified | | currentfile.length ()! = Le Ngth) {if (Count >) {String message = "File Copy time too long.                        Please check copy whether exception! "+" \ n "+" File at: "+ file.getabsolutepath () +" \ n "                + "File Current length is:" + currentfile.lastmodified (); New IllegalStateException (message);            } count++;            Modified = Currentfile.lastmodified ();            Length = Currentfile.length (); try {thread.sleep (500);//wait 500 milliseconds} catch (Interruptedexception e) {//TODO Auto            -generated Catch block E.printstacktrace ();        } currentfile = new File (File.getabsolutepath ()); }//Until the file transfer is complete you can exit}

After modification, the jar package is uploaded to Flume to replace the original jar.

Flume-ng spooldir distributed Log Collection directory monitoring

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.