SlideShare a Scribd company logo
Dive into Fluent P
                         lugin



2012   2   4
Site:
       repeatedly.github.com



       Company:
       Preferred Infrastructure, Inc.



       Love plugins:
       input: tail
       buffer: memory
       output: mongo
2012   2   4
What's Fluentd?
               The missing log collector
                                      See keynote

                       developed by




2012   2   4
Fluentd is a
   buffer
   router
   collector
   converter
   aggregator
   etc...
2012   2   4
... but,
   Fluentd doesn’t have such features as a built-in.




2012   2   4
Instead,
   Fluentd has flexible plugin architecture
   which consists of Input, Output and Buffer.




2012   2   4
We can customize Fluentd using plugins :)




2012   2   4
Agenda
               Yes, I talk about
               - an example of Fluentd plugins
               - Fluentd and libraries
               - how to develop a Fluentd plugins


               No, I don’t talk about
               - the details of each plugin
               - the experience of production

2012   2   4
Example
               based on bit.ly/fluentd-with-mongo




2012   2   4
Install

               Plugin name is fluent-plugin-xxx ,
               and fluent-gem is included in Fluentd gem.




2012   2   4
Let’s type!


               $ fluent-gem install fluent-plugin-mongo




2012   2   4
Me!


              Many
              Many
              Many
           Plugins!
2012   2   4
fluentd.conf

                Input           Output
       <source>             <match mongo.**>
        type tail            type mongo
        format apache        database apache
        path /path/to/log    collection access
        tag mongo.apache     host otherhost
       </source>            </match>

2012   2   4
Start!


               $ fluentd -c fluentd.conf
               2012-02-04 00:00:14 +0900: starting fluentd-0.10.8
               2012-02-04 00:00:14 +0900: reading config file path="fluentd.conf"
               2012-02-04 00:00:14 +0900: adding source type="tail"
               2012-02-04 00:00:14 +0900: adding match pattern="mongo.**" type="mongo"




2012   2   4
Attack!


               $ ab -n 100 -c 10 http://localhost/




2012   2   4
$ mongo --host otherhost
           > use apache
           > db.access.find()
            {
              "type": "127.0.0.1",
              "method": "GET",
              "path": "/",
              "code": "200",
              "size": "44",
              "time": ISODate("2011-11-27T07:56:27Z")
              ...
             }
           has more...
2012   2   4
Apache              I’m a log!

                                    tail

               write

                                                insert
                                   Fluentd
                       event
                       buffering           Mongo
2012   2   4
Warming up

2012   2   4
Fluentd Stack
                       Output
               Input
                       Buffer
                                Ruby
               MessagePack
                 Cool.io
                        OS
2012   2   4
Ruby
               ruby-lang.org




2012   2   4
Fluentd and plugins are written in Ruby.




2012   2   4
... but note that
               Fluentd works on Ruby 1.9, goodbye 1.8!




2012   2   4
MessagePack
                  msgpack.org




2012   2   4
Serialization:
       JSON like fast and compact format.



       RPC:
       Async and parallelism for high performance.



       IDL:
       Easy to integrate and maintain the service.


2012   2   4
Binary format,
               Header + Body,
               and
               Variable length.




2012   2   4
Note that
               Ruby version can’t handle a Time object.




2012   2   4
So,
               we use an Integer object instead of a Time.




2012   2   4
Source:
       github.com/msgpack



       Wiki:
       wiki.msgpack.org/display/MSGPACK



       Mailing List:
       groups.google.com/group/msgpack


2012   2   4
Cool.io
               coolio.github.com




2012   2   4
Event driven framework built on top of   libev.




2012   2   4
Cool.io has Loop and Watchers with
               Transport wrappers.




2012   2   4
Fluentd has a default event loop.
               We can use @default_loop in the plugin.




2012   2   4
Configuration

2012   2   4
Fluentd loads plugins from $LOAD_PATH.




2012   2   4
Input:
       $LOAD_PATH/fluent/plugin/in_<type>.rb



       Buffer:
       $LOAD_PATH/fluent/plugin/buf_<type>.rb



       Output:
       $LOAD_PATH/fluent/plugin/out_<type>.rb


2012   2   4
We use ‘register_input’, ‘register_buffer’
               and ‘register_output’ to register a plugin.




2012   2   4
We can load the plugin configuration using
               config_param and configure method.
               config_param set config value to
               @<config name> automatically.




2012   2   4
<source>
                type tail
                path /path/to/log
                ...
               </source>                   fluentd.conf



           class TailInput < Input
            Plugin.register_input(’tail’, self)
            config_param :path, :string
            ...
           end                                  in_tail.rb
2012   2   4
One trick is here:

               Fluentd’s configuration module does not
               verify a default value. So,
               we can use the nil like Tribool :)

                config_param :tag, :string, :default => nil

                      Fluentd does not check the type

2012   2   4
Fluentd provides some useful mixins for
               input and output plugins.




2012   2   4
SetTagKeyMixin:
       Provide ‘tag_key’ and ‘include_tag_key’.



       SetTimeKeyMixin:
       Provide ‘time_key’ and ‘include_time_key’.



       DetachMultiProcessMixin:
       Provide ‘detach_process’ and
       execute an action in the multi-process.

2012   2   4
Mixin usage
                Code                   Flow
                                           super
       class MongoOutput <
                BufferedOutput      BufferedOutput
        ...                                super
        include SetTagKeyMixin
        config_set_default          SetTagKeyMixin
          :include_tag_key, false
                                           super
        ...
       end                           MongoOutput
2012   2   4
Input

2012   2   4
Available plugins

               Default     3rd party
               exec         mongo_tail
               forward      scribe
               http         msgpack
               stream       dstat
               syslog       zmq
               tail         amqp
               etc...       etc...
2012   2   4
class NewInput < Input
                ...
                def configure(conf)
                  # parse a configuration manually
                end

                def start
                 # invoke action
                end

                def shutdown
                 # cleanup resources
                end
               end
2012   2   4
In action method,
               we use Engine.emit to input data.

                       tag = "app.tag"
                       time = Engine.now
               Sample:
                       record = {"key" => "value", ...}
                       Engine.emit(tag, time, record)

2012   2   4
How to read an input in an efficient way?
               We use a thread and an event loop.




2012   2   4
Thread
               class ForwardInput < Fluent::Input
                ...
                def start
                  ...
                  @thread = Thread.new(&method(:run))
                end

                def run
                 ...
                end
               end
2012   2   4
Event loop
               class ForwardInput < Fluent::Input
                ...
                def start
                  @loop = Coolio::Loop.new
                  @lsock = listen
                  @loop.attach(@lsock)
                  ...
                end
                ...
               end

2012   2   4
Note that
       We must use Engine.now instead of Time.now




2012   2   4
Buffer

2012   2   4
Available plugins

               Default     3rd party

               memory
               file
               zfile (?)



2012   2   4
In most cases,
               Memory and File are enough.




2012   2   4
Memory type is default.
               It’s fast but can’t resume data.




2012   2   4
File type is persistent type.
               It can resume data from file.




2012   2   4
Output

2012   2   4
Available plugins

               Default     3rd party
               copy          mongo
               exec          s3
               file          scribe
               forward       couch
               null          hoop
               stdout        splunk
               etc...        etc...
2012   2   4
class NewOutput < BufferedOutput
                # configure, start and shutdown
                # are same as input plugin

                def format(tag, time, record)
                 # convert event to raw string
                end

                def write(chunk)
                 # write chunk to target
                 # chunk has multiple formatted data
                end
               end

2012   2   4
Output has 3 buffering modes.
                          None
                          Buffered
                          Time sliced




2012   2   4
Buffering type

               Buffered           Time sliced
  from in
                                 Buffer has an internal
                chunk            map to manage a chunk.
                                 A key is tag in Buffered,
 chunk                  queue    but a key is time slice in
 limit          chunk   limit    TimeSliced buffer.

                        go out   def write(chunk)
                chunk             # chunk.key is time slice
                                 end
2012   2   4
How to write an output in an efficient way?
               We can use multi-process (input too).

               See: DetachMultiProcessMixin
                    with detach_multi_process



2012   2   4
Test

2012   2   4
Input:
       Fluent::Test::InputTestDriver



       Buffer:
       Fluent::Test::BufferedOutputTestDriver



       Output:
       Fluent::Test::OutputTestDriver


2012   2   4
class MongoOutputTest < Test::Unit::TestCase
                def setup
                 Fluent::Test.setup
                 require 'fluent/plugin/out_mongo'
                end
               def create_driver(conf = CONFIG)
                Fluent::Test::BufferedOutputTestDriver.new
                 (Fluent::MongoOutput) {
                 def start # prevent external access
                  super
                 end
                 ...
                }.configure(conf)
               end

2012   2   4
...
               def test_format
                 # test format using emit and expect_format
               end
               def test_write
                d = create_driver
                t = emit_documents(d)
                # return a result of write method
                collection_name, documents = d.run
                assert_equal([{...}, {...}, ...], documents)
                assert_equal('test', collection_name)
               end
               ...
               end

2012   2   4
It’s a weak point in Fluentd... right?




2012   2   4
Release

2012   2   4
Gem Structure
               Plugin root
               |-- lib/
               | |-- fluent/
               |        |-- plugin/
               |              |- out_<name>.rb
               |- Gemfile
               |- fluent-plugin-<name>.gemspec
               |- Rakefile
               |- README.md(rdoc)
               |- VERSION
2012   2   4
Bundle with git
               $ edit lib/fluent/plugin/out_<name>.rb

               $ git add / commit

               $ cat VERSION
               0.1.0

               $ bunlde exec rake release
               See: rubygems.org/gems/fluent-plugin-<name>
2012   2   4
See released plugins
               for more details about each file.




2012   2   4
Lastly...

2012   2   4
Help!
2012   2   4
Question?

2012   2   4

More Related Content

What's hot (20)

ODP
An introduction to Apache Thrift
Mike Frampton
 
PDF
Apache Thrift
knight1128
 
PDF
Fluentd v1.0 in a nutshell
N Masahiro
 
PDF
Fluentd Unified Logging Layer At Fossasia
N Masahiro
 
PDF
Modern Black Mages Fighting in the Real World
SATOSHI TAGOMORI
 
PDF
Fluentd v1 and future at techtalk
N Masahiro
 
PDF
Apache thrift-RPC service cross languages
Jimmy Lai
 
PDF
upload test 1
Sadayuki Furuhashi
 
PPTX
Python at Facebook
Angelo Failla
 
PPT
Stackless Python In Eve
l xf
 
PDF
System Programming and Administration
Krasimir Berov (Красимир Беров)
 
PDF
Fluentd v0.14 Overview
N Masahiro
 
PDF
The Parenscript Common Lisp to JavaScript compiler
Vladimir Sedach
 
PDF
httpd — Apache Web Server
webhostingguy
 
PDF
How PHP works
Atlogys Technical Consulting
 
PDF
RESTLess Design with Apache Thrift: Experiences from Apache Airavata
smarru
 
PDF
parenscript-tutorial
tutorialsruby
 
ODP
Snaps on open suse
Zygmunt Krynicki
 
PDF
Lesson 9. The Apache Web Server
webhostingguy
 
PPT
Firebird Security (in English): The Past and The Future
Alexey Kovyazin
 
An introduction to Apache Thrift
Mike Frampton
 
Apache Thrift
knight1128
 
Fluentd v1.0 in a nutshell
N Masahiro
 
Fluentd Unified Logging Layer At Fossasia
N Masahiro
 
Modern Black Mages Fighting in the Real World
SATOSHI TAGOMORI
 
Fluentd v1 and future at techtalk
N Masahiro
 
Apache thrift-RPC service cross languages
Jimmy Lai
 
upload test 1
Sadayuki Furuhashi
 
Python at Facebook
Angelo Failla
 
Stackless Python In Eve
l xf
 
System Programming and Administration
Krasimir Berov (Красимир Беров)
 
Fluentd v0.14 Overview
N Masahiro
 
The Parenscript Common Lisp to JavaScript compiler
Vladimir Sedach
 
httpd — Apache Web Server
webhostingguy
 
RESTLess Design with Apache Thrift: Experiences from Apache Airavata
smarru
 
parenscript-tutorial
tutorialsruby
 
Snaps on open suse
Zygmunt Krynicki
 
Lesson 9. The Apache Web Server
webhostingguy
 
Firebird Security (in English): The Past and The Future
Alexey Kovyazin
 

Similar to Fluentd meetup dive into fluent plugin (outdated) (20)

PDF
Fluentd meetup
Sadayuki Furuhashi
 
PDF
Dive into Fluentd plugin v0.12
N Masahiro
 
PDF
Fluentd meetup in japan
Treasure Data, Inc.
 
PDF
The basics of fluentd
Treasure Data, Inc.
 
PDF
Fluentd meetup at Slideshare
Sadayuki Furuhashi
 
PDF
How to collect Big Data into Hadoop
Sadayuki Furuhashi
 
PDF
Fluentd introduction at ipros
Treasure Data, Inc.
 
PDF
Fluentd unified logging layer
Kiyoto Tamura
 
PDF
The basics of fluentd
Treasure Data, Inc.
 
KEY
Fluentd: the missing log collector
td_kiyoto
 
PDF
Fluentd and Embulk Game Server 4
N Masahiro
 
PDF
Treasure Data Summer Internship 2016
Yuta Iwama
 
PDF
Fluentd - RubyKansai 65
N Masahiro
 
PDF
Fluentd 101
SATOSHI TAGOMORI
 
PDF
Collect distributed application logging using fluentd (EFK stack)
Marco Pas
 
PDF
Fluentd v11 at tokuben
Treasure Data, Inc.
 
PDF
Fluentd meetup #2
Treasure Data, Inc.
 
PDF
Fluentd Overview, Now and Then
SATOSHI TAGOMORI
 
PDF
Plugins by tagomoris #fluentdcasual
SATOSHI TAGOMORI
 
PDF
Fluentd: Unified Logging Layer at CWT2014
N Masahiro
 
Fluentd meetup
Sadayuki Furuhashi
 
Dive into Fluentd plugin v0.12
N Masahiro
 
Fluentd meetup in japan
Treasure Data, Inc.
 
The basics of fluentd
Treasure Data, Inc.
 
Fluentd meetup at Slideshare
Sadayuki Furuhashi
 
How to collect Big Data into Hadoop
Sadayuki Furuhashi
 
Fluentd introduction at ipros
Treasure Data, Inc.
 
Fluentd unified logging layer
Kiyoto Tamura
 
The basics of fluentd
Treasure Data, Inc.
 
Fluentd: the missing log collector
td_kiyoto
 
Fluentd and Embulk Game Server 4
N Masahiro
 
Treasure Data Summer Internship 2016
Yuta Iwama
 
Fluentd - RubyKansai 65
N Masahiro
 
Fluentd 101
SATOSHI TAGOMORI
 
Collect distributed application logging using fluentd (EFK stack)
Marco Pas
 
Fluentd v11 at tokuben
Treasure Data, Inc.
 
Fluentd meetup #2
Treasure Data, Inc.
 
Fluentd Overview, Now and Then
SATOSHI TAGOMORI
 
Plugins by tagomoris #fluentdcasual
SATOSHI TAGOMORI
 
Fluentd: Unified Logging Layer at CWT2014
N Masahiro
 
Ad

More from N Masahiro (19)

PDF
Fluentd Project Intro at Kubecon 2019 EU
N Masahiro
 
PDF
Fluentd and Distributed Logging at Kubecon
N Masahiro
 
PDF
Presto changes
N Masahiro
 
PDF
Fluentd and Kafka
N Masahiro
 
PDF
fluent-plugin-beats at Elasticsearch meetup #14
N Masahiro
 
PDF
Technologies for Data Analytics Platform
N Masahiro
 
PDF
Docker and Fluentd
N Masahiro
 
PDF
How to create Treasure Data #dotsbigdata
N Masahiro
 
PDF
Treasure Data and AWS - Developers.io 2015
N Masahiro
 
PDF
Treasure Data and OSS
N Masahiro
 
PDF
Fluentd - road to v1 -
N Masahiro
 
PDF
SQL for Everything at CWT2014
N Masahiro
 
PDF
Can you say the same words even in oss
N Masahiro
 
PDF
I am learing the programming
N Masahiro
 
PDF
D vs OWKN Language at LLnagoya
N Masahiro
 
PDF
Goodbye Doost
N Masahiro
 
KEY
Final presentation at pfintern
N Masahiro
 
ZIP
Kernel VM 5 LT
N Masahiro
 
ZIP
D言語のコミッタになる一つの方法
N Masahiro
 
Fluentd Project Intro at Kubecon 2019 EU
N Masahiro
 
Fluentd and Distributed Logging at Kubecon
N Masahiro
 
Presto changes
N Masahiro
 
Fluentd and Kafka
N Masahiro
 
fluent-plugin-beats at Elasticsearch meetup #14
N Masahiro
 
Technologies for Data Analytics Platform
N Masahiro
 
Docker and Fluentd
N Masahiro
 
How to create Treasure Data #dotsbigdata
N Masahiro
 
Treasure Data and AWS - Developers.io 2015
N Masahiro
 
Treasure Data and OSS
N Masahiro
 
Fluentd - road to v1 -
N Masahiro
 
SQL for Everything at CWT2014
N Masahiro
 
Can you say the same words even in oss
N Masahiro
 
I am learing the programming
N Masahiro
 
D vs OWKN Language at LLnagoya
N Masahiro
 
Goodbye Doost
N Masahiro
 
Final presentation at pfintern
N Masahiro
 
Kernel VM 5 LT
N Masahiro
 
D言語のコミッタになる一つの方法
N Masahiro
 
Ad

Recently uploaded (20)

PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PPTX
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
PPTX
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Build with AI and GDG Cloud Bydgoszcz- ADK .pdf
jaroslawgajewski1
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
The Future of Artificial Intelligence (AI)
Mukul
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Introduction to Flutter by Ayush Desai.pptx
ayushdesai204
 
Agile Chennai 18-19 July 2025 | Workshop - Enhancing Agile Collaboration with...
AgileNetwork
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 

Fluentd meetup dive into fluent plugin (outdated)

  • 1. Dive into Fluent P lugin 2012 2 4
  • 2. Site: repeatedly.github.com Company: Preferred Infrastructure, Inc. Love plugins: input: tail buffer: memory output: mongo 2012 2 4
  • 3. What's Fluentd? The missing log collector See keynote developed by 2012 2 4
  • 4. Fluentd is a buffer router collector converter aggregator etc... 2012 2 4
  • 5. ... but, Fluentd doesn’t have such features as a built-in. 2012 2 4
  • 6. Instead, Fluentd has flexible plugin architecture which consists of Input, Output and Buffer. 2012 2 4
  • 7. We can customize Fluentd using plugins :) 2012 2 4
  • 8. Agenda Yes, I talk about - an example of Fluentd plugins - Fluentd and libraries - how to develop a Fluentd plugins No, I don’t talk about - the details of each plugin - the experience of production 2012 2 4
  • 9. Example based on bit.ly/fluentd-with-mongo 2012 2 4
  • 10. Install Plugin name is fluent-plugin-xxx , and fluent-gem is included in Fluentd gem. 2012 2 4
  • 11. Let’s type! $ fluent-gem install fluent-plugin-mongo 2012 2 4
  • 12. Me! Many Many Many Plugins! 2012 2 4
  • 13. fluentd.conf Input Output <source> <match mongo.**> type tail type mongo format apache database apache path /path/to/log collection access tag mongo.apache host otherhost </source> </match> 2012 2 4
  • 14. Start! $ fluentd -c fluentd.conf 2012-02-04 00:00:14 +0900: starting fluentd-0.10.8 2012-02-04 00:00:14 +0900: reading config file path="fluentd.conf" 2012-02-04 00:00:14 +0900: adding source type="tail" 2012-02-04 00:00:14 +0900: adding match pattern="mongo.**" type="mongo" 2012 2 4
  • 15. Attack! $ ab -n 100 -c 10 http://localhost/ 2012 2 4
  • 16. $ mongo --host otherhost > use apache > db.access.find() { "type": "127.0.0.1", "method": "GET", "path": "/", "code": "200", "size": "44", "time": ISODate("2011-11-27T07:56:27Z") ... } has more... 2012 2 4
  • 17. Apache I’m a log! tail write insert Fluentd event buffering Mongo 2012 2 4
  • 19. Fluentd Stack Output Input Buffer Ruby MessagePack Cool.io OS 2012 2 4
  • 20. Ruby ruby-lang.org 2012 2 4
  • 21. Fluentd and plugins are written in Ruby. 2012 2 4
  • 22. ... but note that Fluentd works on Ruby 1.9, goodbye 1.8! 2012 2 4
  • 23. MessagePack msgpack.org 2012 2 4
  • 24. Serialization: JSON like fast and compact format. RPC: Async and parallelism for high performance. IDL: Easy to integrate and maintain the service. 2012 2 4
  • 25. Binary format, Header + Body, and Variable length. 2012 2 4
  • 26. Note that Ruby version can’t handle a Time object. 2012 2 4
  • 27. So, we use an Integer object instead of a Time. 2012 2 4
  • 28. Source: github.com/msgpack Wiki: wiki.msgpack.org/display/MSGPACK Mailing List: groups.google.com/group/msgpack 2012 2 4
  • 29. Cool.io coolio.github.com 2012 2 4
  • 30. Event driven framework built on top of libev. 2012 2 4
  • 31. Cool.io has Loop and Watchers with Transport wrappers. 2012 2 4
  • 32. Fluentd has a default event loop. We can use @default_loop in the plugin. 2012 2 4
  • 34. Fluentd loads plugins from $LOAD_PATH. 2012 2 4
  • 35. Input: $LOAD_PATH/fluent/plugin/in_<type>.rb Buffer: $LOAD_PATH/fluent/plugin/buf_<type>.rb Output: $LOAD_PATH/fluent/plugin/out_<type>.rb 2012 2 4
  • 36. We use ‘register_input’, ‘register_buffer’ and ‘register_output’ to register a plugin. 2012 2 4
  • 37. We can load the plugin configuration using config_param and configure method. config_param set config value to @<config name> automatically. 2012 2 4
  • 38. <source> type tail path /path/to/log ... </source> fluentd.conf class TailInput < Input Plugin.register_input(’tail’, self) config_param :path, :string ... end in_tail.rb 2012 2 4
  • 39. One trick is here: Fluentd’s configuration module does not verify a default value. So, we can use the nil like Tribool :) config_param :tag, :string, :default => nil Fluentd does not check the type 2012 2 4
  • 40. Fluentd provides some useful mixins for input and output plugins. 2012 2 4
  • 41. SetTagKeyMixin: Provide ‘tag_key’ and ‘include_tag_key’. SetTimeKeyMixin: Provide ‘time_key’ and ‘include_time_key’. DetachMultiProcessMixin: Provide ‘detach_process’ and execute an action in the multi-process. 2012 2 4
  • 42. Mixin usage Code Flow super class MongoOutput < BufferedOutput BufferedOutput ... super include SetTagKeyMixin config_set_default SetTagKeyMixin :include_tag_key, false super ... end MongoOutput 2012 2 4
  • 43. Input 2012 2 4
  • 44. Available plugins Default 3rd party exec mongo_tail forward scribe http msgpack stream dstat syslog zmq tail amqp etc... etc... 2012 2 4
  • 45. class NewInput < Input ... def configure(conf) # parse a configuration manually end def start # invoke action end def shutdown # cleanup resources end end 2012 2 4
  • 46. In action method, we use Engine.emit to input data. tag = "app.tag" time = Engine.now Sample: record = {"key" => "value", ...} Engine.emit(tag, time, record) 2012 2 4
  • 47. How to read an input in an efficient way? We use a thread and an event loop. 2012 2 4
  • 48. Thread class ForwardInput < Fluent::Input ... def start ... @thread = Thread.new(&method(:run)) end def run ... end end 2012 2 4
  • 49. Event loop class ForwardInput < Fluent::Input ... def start @loop = Coolio::Loop.new @lsock = listen @loop.attach(@lsock) ... end ... end 2012 2 4
  • 50. Note that We must use Engine.now instead of Time.now 2012 2 4
  • 51. Buffer 2012 2 4
  • 52. Available plugins Default 3rd party memory file zfile (?) 2012 2 4
  • 53. In most cases, Memory and File are enough. 2012 2 4
  • 54. Memory type is default. It’s fast but can’t resume data. 2012 2 4
  • 55. File type is persistent type. It can resume data from file. 2012 2 4
  • 56. Output 2012 2 4
  • 57. Available plugins Default 3rd party copy mongo exec s3 file scribe forward couch null hoop stdout splunk etc... etc... 2012 2 4
  • 58. class NewOutput < BufferedOutput # configure, start and shutdown # are same as input plugin def format(tag, time, record) # convert event to raw string end def write(chunk) # write chunk to target # chunk has multiple formatted data end end 2012 2 4
  • 59. Output has 3 buffering modes. None Buffered Time sliced 2012 2 4
  • 60. Buffering type Buffered Time sliced from in Buffer has an internal chunk map to manage a chunk. A key is tag in Buffered, chunk queue but a key is time slice in limit chunk limit TimeSliced buffer. go out def write(chunk) chunk # chunk.key is time slice end 2012 2 4
  • 61. How to write an output in an efficient way? We can use multi-process (input too). See: DetachMultiProcessMixin with detach_multi_process 2012 2 4
  • 62. Test 2012 2 4
  • 63. Input: Fluent::Test::InputTestDriver Buffer: Fluent::Test::BufferedOutputTestDriver Output: Fluent::Test::OutputTestDriver 2012 2 4
  • 64. class MongoOutputTest < Test::Unit::TestCase def setup Fluent::Test.setup require 'fluent/plugin/out_mongo' end def create_driver(conf = CONFIG) Fluent::Test::BufferedOutputTestDriver.new (Fluent::MongoOutput) { def start # prevent external access super end ... }.configure(conf) end 2012 2 4
  • 65. ... def test_format # test format using emit and expect_format end def test_write d = create_driver t = emit_documents(d) # return a result of write method collection_name, documents = d.run assert_equal([{...}, {...}, ...], documents) assert_equal('test', collection_name) end ... end 2012 2 4
  • 66. It’s a weak point in Fluentd... right? 2012 2 4
  • 68. Gem Structure Plugin root |-- lib/ | |-- fluent/ | |-- plugin/ | |- out_<name>.rb |- Gemfile |- fluent-plugin-<name>.gemspec |- Rakefile |- README.md(rdoc) |- VERSION 2012 2 4
  • 69. Bundle with git $ edit lib/fluent/plugin/out_<name>.rb $ git add / commit $ cat VERSION 0.1.0 $ bunlde exec rake release See: rubygems.org/gems/fluent-plugin-<name> 2012 2 4
  • 70. See released plugins for more details about each file. 2012 2 4
  • 72. Help! 2012 2 4