44
FLUENTD 101 BOOTSTRAP OF UNIFIED LOGGING Open Source Summit Japan 2017 Fluentd Mini Summit / June 1, 2017 Satoshi Tagomori (@tagomoris) Treasure Data, Inc.

Fluentd 101

Embed Size (px)

Citation preview

Page 1: Fluentd 101

FLUENTD 101 BOOTSTRAP OF UNIFIED LOGGING

Open Source Summit Japan 2017 Fluentd Mini Summit / June 1, 2017

Satoshi Tagomori (@tagomoris) Treasure Data, Inc.

Page 2: Fluentd 101

Satoshi "Moris" Tagomori (@tagomoris)

Fluentd, MessagePack-Ruby, Norikra, ...

Treasure Data, Inc.

Page 3: Fluentd 101
Page 4: Fluentd 101

What is Fluentd?

Page 5: Fluentd 101
Page 6: Fluentd 101
Page 7: Fluentd 101

"Fluentd is an open source data collector for unified logging layer."

https://www.fluentd.org/

Page 8: Fluentd 101

"Unified Logging Layer" ?

"Fluentd decouples data sources from backend systems by providing a unified logging layer in between."

SQL

Page 9: Fluentd 101

"Unified Logging Layer" ?

"Fluentd decouples data sources from backend systems by providing a unified logging layer in between."

SQL

Unified Logging

Layer

Page 10: Fluentd 101

"Unified Logging Layer" ?

"Fluentd decouples data sources from backend systems by providing a unified logging layer in between."

SQL

Page 11: Fluentd 101

"Unified Logging Layer" ?

"Fluentd decouples data sources from backend systems by providing a unified logging layer in between."

SQL

Page 12: Fluentd 101

AN EXTENSIBLE & RELIABLE DATA COLLECTION TOOL

Simple Core w/ Plugin System+

Various Plugins

Buffering, Retries, Failover

Page 13: Fluentd 101

# logs from a file<source> @type tail path /var/log/httpd.log pos_file /tmp/pos_file tag web.access <parse> @type apache2 </parse></source>

# logs from client libraries<source> @type forward port 24224</source>

# store logs to ES and HDFS<match web.*> @type copy <store> @type elasticsearch logstash_format true </store> <store> @type webhdfs host namenode.local port 50070 path /path/on/hdfs <format> @type json </format> </store></match>

Configuration (v0.14)

Page 14: Fluentd 101

Implementation / Performance

• Fluentd is written in Ruby

• C extension libraries for performance requirement

• cool.io: Asynchronous I/O

• msgpack: Serialization/Deserialization for MessagePack

• Plugins in Ruby - easy to join the community

• Scaling for CPU cores

• multiprocess plugin (~ v0.12)

• multi process workers (v0.14 ~)

Page 15: Fluentd 101

Package / Deployment

• Fluentd released on RubyGems.org

• rpm/deb package

• td-agent by Treasure Data

• Fluentd + some widely-used plugins

• td-agent2: Fluentd v0.12

• td-agent3 (beta now): Fluentd v0.14 (or v1)

• + msi package for Windows

• Docker images

• https://hub.docker.com/r/fluent/fluentd/

Page 16: Fluentd 101

For Users in the Enterprise Sector

More security features and some others

https://fluentd.treasuredata.com/

Page 17: Fluentd 101

Plugin System

Page 18: Fluentd 101

3rd party input plugins

dstat

df AMQL

munin

jvmwatcher

SQL

Page 19: Fluentd 101

3rd party output plugins

Graphite

Page 20: Fluentd 101

Buffer OutputParserInput FormatterFilter

“output-ish”“input-ish”

“output-ish”“input-ish”Storage

Helper

Buffer OutputParserInput FormatterFilter

Fluentd v0.14

Fluentd v0.12

Page 21: Fluentd 101

Plugins

• Built-in plugins

• tail, forward, file, exec, exec_filter, copy, ...

• 3rd party plugins (755 plugins at May 19)

• fluent-plugin-xxx via rubygems.org

• webhdfs, kafka, elasticsearch, redshift, bigquery, ...

• Plugin script

• .rb script files on /etc/fluent/plugin

Page 22: Fluentd 101

Ecosystem

Page 23: Fluentd 101
Page 24: Fluentd 101
Page 25: Fluentd 101
Page 26: Fluentd 101

Events

Page 27: Fluentd 101

Events: Structured Logs

ec_service.shopping_cart

2017-03-30 16:35:37 +0100

{"container_id": "bfdd5b9....","container_name": "/infallible_mayer","source": "stdout","event": "put an item to cart","item_id": 101,"items": 10,"client": "web"}

tagtimestamp

record

Page 28: Fluentd 101

Event: tag, timestamp and record

• Tag

• A dot-separated string

• to show what the event is / where the event from

• Timestamp

• An integer of unix time (~ v0.12)

• A structured timestamp with nano seconds (v0.14 ~)

• Record

• Key-value pairs

Page 29: Fluentd 101

Data Source

router

input plugin

read / receiveraw data

eventeventeventevent

parser plugin

parse data into key-valuesparse timestamp from record

add tags

output plugin with buffering

eventeventeventevent

format plugin

buffer plugin

formatted data

Data Destination

write / send

Page 30: Fluentd 101

Buffers and Retries

Page 31: Fluentd 101

Buffer & Retry for Micro-Try&Error

Retry

Retry

Batch

Stream Error

Retry

Retry

Page 32: Fluentd 101

Controlled Recovery from Long OutageBuffer (on-disk or in-memory)

Error

Overloaded!!

recovery

recovery + flow control

queued chunks

Page 33: Fluentd 101

Last Resort: Secondary Output

Error

queued chunks

Page 34: Fluentd 101

# store logs to ES, or file if it goes down<match web.*> @type elasticsearch logstash_format true <secondary> @type secondary_file path /data/backup/web </secondary></match>

Configuration: Secondary Output (v0.14)

Page 35: Fluentd 101

Forwarding Data via Network

Page 36: Fluentd 101

Forward Plugin: Forwarding Data via Network• Built-in plugin, TCP port 24224 (in default)

• with heartbeat protocol (default UDP in v0.12, TCP/TLS in v0.14)

• Transfer data via TCP

• From Fluentd to Fluentd

• From logger libraries to Fluentd

• From Fluent-bit to Fluentd

• From Docker logging driver to Fluentd

• Standard protocol

https://github.com/fluent/fluentd/wiki/Forward-Protocol-Specification-v1(Spec v0 at Fluentd v0.12 or earlier -> Spec v1 at Fluentd 0.14)

Page 37: Fluentd 101

Forward: Features• Load Balancing / High Availability

• Servers with weights

• Standby servers

• DNS round robin

• Controlling Data Transferring Semantics

• at-most-once / at-least-once transferring

• Spec v1 Features

• TLS support

• Simple authentication/authorization

• Efficient data transferring: Gzip Compression (v0.14)

Page 38: Fluentd 101

Forward Plugin: Load Balancing

60

60

60

60

60

60

60

20

weight: 60 (default)

weight: 60 (default)

weight: 60 (default)

weight: 20

Balance Data with Configured Weight

Page 39: Fluentd 101

Forward Plugin: Handling Server Failure

Detecting Server Down/Up using Heartbeat

Error

Page 40: Fluentd 101

Forward Plugin: Standby Server

Detecting Server Down/Up using Heartbeat

standby: true

Error

standby: true

Page 41: Fluentd 101

Forward Plugin: Without ACK (at-most-once)

forward outputbuffer

forward input any output

forward output forward input any outputbufferbuffer

Without any troubles

With troubles about buffers in destination

forward outputbuffer

forward input any output

forward output forward input any outputbuffer buffer

Events will be lost in this case :(

Page 42: Fluentd 101

Forward Plugin: With ACK (at-least-once)

forward outputbuffer

forward input any output

forward output forward input any outputbuffer

Forward output:require_ack_response: true

forward output forward input any outputbuffer

buffer

buffer ACKwith chunk id

forward output forward input any outputbufferbuffer

with chunk id

Page 43: Fluentd 101

Forward Plugin: With ACK (at-least-once)

forward outputbuffer

forward input any output

forward output forward input any output

Forward output:require_ack_response: true

forward output forward input any output

buffer

buffer ACK missing

forward output forward input any output

with chunk id

buffer

buffer

with chunk id

retry

Forward output ensure to transfer buffers to any living destinations :D

Page 44: Fluentd 101

Fluentd has many good stuffsfor logging.

Discover more on docs.fluentd.org!

Happy Logging! @tagomoris