How to merge multiple log files

Source: Internet
Author: User

How to merge multiple log files?
The following uses the standard CLF format log (APACHE) as an example:
The log format of Apche is as follows:
% H % L % u % t/"% R/" %> S % B
Example:
111.222.111.222--[03/APR/2002: 10: 30: 17 + 0800] "Get/index.html HTTP/1.1"

200 419

The simplest idea is to read the logs one by one and sort them by the time field in the log.
Cat log1 log2 log3 | sort-K 4-T ""
Note:
-T "": the log field delimiter is a space.
-K 4: sort by 4th fields, that is, [03/APR/2002: 10: 30: 17 + 0800 ].
-O log_all: output to the log_all file.

However, the efficiency is relatively low. If a service already needs Server Load balancer

The number of logs is usually more than 10 million, and the size is several hundred mb. In this way, multiple logs of hundreds of MB need to be arranged at the same time.

Order, machine load can be thought ......
In fact, there is a way to optimize, you know: even if a single log itself is already a "time-based arrangement

And sort provides an optimized merge algorithm for sorting and merging of such files: Use-m

Merge merge option,
Therefore, it is better to merge the three log files log1 log2 log3 in this format and output them to log_all.

:
Sort-m-T ""-K 4-O log_all log1 log2 log3
Note:
-M: Use the merge optimization algorithm

Note: It is best to compress the merged log output and then send it to Webalizer for processing.
Some systems can process 2 GB of files, and some cannot. Some programs can process files larger than 2 GB, and some cannot. Do

Avoid files larger than 2 GB, unless it is confirmed that all programs and operating systems involved in the processing can process such files

. Therefore, if the output file is greater than 2 GB, it is better to zip the log and send it to Webalizer for processing: larger than 2 GB

During file analysis, the possibility of file system errors is relatively high, and gzip can also greatly reduce

I/O operations.

This is how logs are merged in chronological order.

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.