{"id":37898,"date":"2016-07-28T10:41:00","date_gmt":"2016-07-28T05:11:00","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=37898"},"modified":"2016-07-30T06:01:13","modified_gmt":"2016-07-30T00:31:13","slug":"fluentd-the-log-collector","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/fluentd-the-log-collector\/","title":{"rendered":"Fluentd &#8211; The Log Collector"},"content":{"rendered":"<h1 style=\"text-align: center;\"><\/h1>\n<p>Whenever we talk about Log Analysis which is to create some sense out of the computer generated records, we always need some tools which can first collect these logs from different devices, operating systems or any applications. These tools are generally termed as Log Collectors.<\/p>\n<p><span style=\"font-weight: 400;\">There are two popular log collectors &#8211; <\/span><a href=\"http:\/\/www.tothenew.com\/blog\/building-a-central-log-server-with-logstash\/\"><span style=\"font-weight: 400;\">Logstash<\/span><\/a><span style=\"font-weight: 400;\"> &amp; Fluentd. Logstash is written in JRuby and is maintained by elastic.co. However, Fluentd is written in CRuby and is maintained by <\/span><span style=\"font-weight: 400;\">Treasure Data Inc<\/span><span style=\"font-weight: 400;\">.<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-37965 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/fluentd.png\" alt=\"fluentd\" width=\"221\" height=\"228\" \/><\/p>\n<p>Fluentd works on Unified Logging Layer means it tries to structure logs as JSON as much as possible. The idea is to\u00a0provide an interface which can be used by almost any producer or any consumer of the\u00a0logs. This helps in all phases of log processing like Collection, Filter, and Output\/Display.<\/p>\n<p><span style=\"font-weight: 400;\">Like Logstash, it also provides 300+ plugins out of which only a\u00a0few are provided by official Fluentd repo and a majority of them are maintained by individuals.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It can easily be replaced with Logstash as a log collector subject to some pros and cons in existing ELK stack making it EFK stack. Unlike Logstash which works with Aggregation of logs from different sources, Fluentd works on Routing on the basis of TAGs assigned on each input.<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Lifecycle of Fluentd Event:<\/strong><\/h2>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-37966 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Fluentd_lifecycle.png\" alt=\"Fluentd_lifecycle\" width=\"720\" height=\"540\" \/><\/p>\n<p>&nbsp;<\/p>\n<h2><strong>Basic Directives Involved<\/strong><\/h2>\n<p><strong>source<\/strong><span style=\"font-weight: 400;\"><strong>: <\/strong>\u00a0This mandatory directive is required to define the type parameter which specifies which input plugin to use:<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38331\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/source.png\" alt=\"source\" width=\"344\" height=\"211\" \/><\/p>\n<p><b>match: <\/b><span style=\"font-weight: 400;\">\u201cdecide what to do !\u201d \u00a0Each match directive must include a match pattern and a type parameter. Events with a tag matching the pattern will be picked and sent to the output destination. The destination could be Elasticsearch, S3, Mongo or to Treasure Data directly:<\/span><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38330\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/match.png\" alt=\"match\" width=\"379\" height=\"103\" \/><\/p>\n<p><b>filter: \u00a0<\/b><span style=\"font-weight: 400;\">It has same the syntax as \u201cmatch\u201d but \u201cfilter\u201d could be used for further processing before pushing it to output. Using filters, event flow is like below:<\/span><\/p>\n<h2 style=\"text-align: center;\"><span style=\"font-weight: 400;\">Input -&gt; filter 1 -&gt; &#8230; -&gt; filter N -&gt; Output<\/span><\/h2>\n<p><strong><strong>\u00a0<img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-38329\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/filter.png\" alt=\"filter\" width=\"533\" height=\"144\" \/><\/strong><\/strong><\/p>\n<p>In my case, I wanted to forward all Nginx access log to Elasticsearch, I used below configuration using tag \u2018nginx.access\u2019:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-medium wp-image-37968\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/input_tag.png\" alt=\"input_tag\" width=\"291\" height=\"110\" \/><\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-37967\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/output_match.png\" alt=\"output_match\" width=\"196\" height=\"132\" \/><\/p>\n<p><span style=\"font-weight: 400;\">There are multiple pre-defined <\/span><a href=\"http:\/\/docs.fluentd.org\/categories\/recipes\"><span style=\"font-weight: 400;\">recipes<\/span><\/a><span style=\"font-weight: 400;\"> available on Fluentd which you can utilize. Like Logstash, Fluentd also makes use of Regex patterns for the logs whose format is not known or is not already available with Fluentd. Those patterns can be verified on <\/span><a href=\"http:\/\/fluentular.herokuapp.com\/\"><span style=\"font-weight: 400;\">Fluentular<\/span><\/a><span style=\"font-weight: 400;\">. <\/span><\/p>\n<p>Unlike Logstash, which can only be configured as Active-Standby, Fluentd can be configured as Active-Active (Load Balancing mode), Active-Standby mode, Weighted Load Balancing modes.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-37969 size-full\" src=\"\/blog\/wp-ttn-blog\/uploads\/2016\/07\/Fluentd_active-active.png\" alt=\"Fluentd_active-active\" width=\"720\" height=\"540\" \/><\/p>\n<p><span style=\"font-weight: 400;\">Since Fluentd was invented by Treasure Data Inc, TD also provides Fluentd in <\/span><a href=\"https:\/\/docs.treasuredata.com\/articles\/td-agent\"><span style=\"font-weight: 400;\">td-agent<\/span><\/a><span style=\"font-weight: 400;\"> form which is a\u00a0more stable distribution of Fluentd. It supports multiple Installation medium and comes with preconfigured recommended settings.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">So when a Simple, Flexible, Reliable Unified Logging tool is required, you can directly choose Fluentd.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Whenever we talk about Log Analysis which is to create some sense out of the computer generated records, we always need some tools which can first collect these logs from different devices, operating systems or any applications. These tools are generally termed as Log Collectors. There are two popular log collectors &#8211; Logstash &amp; Fluentd. [&hellip;]<\/p>\n","protected":false},"author":181,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":9},"categories":[2348,1],"tags":[3802,3807,3808,3809,1973,3806,3803,3805,3804],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/37898"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/181"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=37898"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/37898\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=37898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=37898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=37898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}