Fluentd: The Missing Log Collector
Join the DZone community and get the full member experience.Join For Free
the fundamental problem with logs is that they are usually stored in files although they are best represented as streams (by adam wiggins, cto at heroku). traditionally, they have been dumped into text-based files and collected by rsync in hourly or daily fashion. with today’s web/mobile applications, this creates two problems.
problem 1: need ad-hoc parsing
the text-based logs have their own format, and analytics engineer need to write a dedicated parser for each format. but that’s probably not the best use of your time. you should be analyzing data to make better business decisions instead of writing one parser after another.
problem 2: lacks freshness
the logs lag. the realtime analysis of user behavior makes feature iterations a lot faster. a nimbler a/b testing will help you differentiate your service from competitors.
this is where fluentd comes in. we believe fluentd solves all issues of scalable log collection by getting rid of files and turning logs into true semi-structured data streams.
the best way to describe fluentd is ‘syslogd that understands json’. the notable features are:
- easy installation by rpm/deb/gem
- small footprint with 3000 lines of ruby
- semi-structured data logging
- easy start with small configuration
- fully pluggable architecture, and plugin distribution by ruby gems
other similar systems are facebook’s scribe and cloudera’s flume. here is a table to summarize the differences among scribe, flume, and fluentd. (note: i don’t know much about next-generation flume ng branch , but big movement is happening to flume!):
of course, there’re pros and cons here. fluentd takes maximum extensibility and flexibility over ruby’s eco-system, while scribe takes the performance (although fluentd is pretty fast too. it can handle 18000msgs/s per core). flume is powered by java and therefore integrates natively with many enterprise systems.
the following sections describe the basic concepts of fluentd in more detail.
logentry = time + tag + record
unlike traditional raw-text log, the log entry of fluentd consists of three entities: time, tag, and record.
- the time is the unix timestamp when the logs are posted.
- the tag is used to route the message in log-forwarding, which is described later.
- the record is represented as json, not raw text.
the record is intentionally represented as json. fluentd is designed to collect semi-structured data, not unstructured data. this means no parsing is required at the later analysis pipeline. it’s easy to handle, and faster than ad-hoc regexp. but the application needs to use the logging library for fluentd.
internal architecture: input -> buffer -> output
fluentd consists of three basic components: input, buffer, and output. the basic behavior is 1) feeding logs from input, 2) buffers them, and 3) forward to output.
input is the place where the log comes in. the user can extend it to feed the events from various sources. the example input supported officially includes: http+json, tailing files (apache log parser is supported), syslog. of course you can add input plugin by writing a ruby plugin.
buffer exists for reliability. when the output fails, the events are kept by buffer and automatically retried. memory or file buffer is supported now.
buffer creates chunks of logs, and passes them to the output. output stores or forwards chunks. the buffer waits several seconds to 1 minute, to create chunks. this is really efficient for writing into the storage which supports batch-style importing.
fluentd works well with one-node, but it can have multi-node configuration.
the application servers have one fluentd locally, and it forwards the local logs into another fluentd, which aggregates all the logs into one place. the tag is used to determine the destination fluentd (static configuration by config files).
fluentd makes real-time log collection dead simple. out of the possible solutions, we believe fluentd is easiest to install, configure, extend, and perform well.
of course it’s an early-stage product compared to scribe and flume, but we already have some users aggregating tens of millions of daily logs using fluentd. the # of committers and plugins are increasing everyday.
Published at DZone with permission of Sadayuki Furuhashi, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.