Fluentd - RubyKansai 65

52
Masahiro Nakagawa Feb 21, 2015 RubyKansai #65 Fluentd Unified logging layer

Transcript of Fluentd - RubyKansai 65

Page 1: Fluentd - RubyKansai 65

Masahiro NakagawaFeb 21, 2015

RubyKansai #65

FluentdUnified logging layer

Page 2: Fluentd - RubyKansai 65

Who are you?

> Masahiro Nakagawa > github/twitter: @repeatedly

> Treasure Data, Inc. > Senior Software Engineer > Fluentd / td-agent developer

> Living at OSS :) > D language - Phobos committer > Fluentd - Main maintainer > MessagePack / RPC - D and Python (only RPC) > The organizer of several meetups (Presto, DTM, etc…) > etc…

Page 3: Fluentd - RubyKansai 65

Structured logging !

Reliable forwarding !

Pluggable architecture

http://fluentd.org/

Page 4: Fluentd - RubyKansai 65

What’s Fluentd?

> Data collector for unified logging layer > Streaming data transfer based on JSON > Written in Ruby

> Gem based various plugins > http://www.fluentd.org/plugins

> Working in production > http://www.fluentd.org/testimonials

Page 5: Fluentd - RubyKansai 65

Background

Page 6: Fluentd - RubyKansai 65

Data Analytics Flow

Collect Store Process Visualize

Data source

Reporting

Monitoring

Page 7: Fluentd - RubyKansai 65

Data Analytics Flow

Store Process

Cloudera

Horton Works

Treasure Data

Collect Visualize

Tableau

Excel

R

easier & shorter time

???

Page 8: Fluentd - RubyKansai 65

TD Service Architecture

Time to Value

Send query result Result Push

Acquire Analyze Store

Plazma DB Flexible, Scalable, Columnar Storage

Web Log

App Log

Censor

CRM

ERP

RDBMS

Treasure Agent(Server) SDK(JS, Android, iOS, Unity)

Streaming Collector

Batch / Reliability

Ad-hoc /Low latency

KPI$

KPI Dashboard

BI Tools

Other Products

RDBMS, Google Docs, AWS S3, FTP Server, etc.

Metric Insights

Tableau, Motion Board�����etc.

POS

REST API ODBC / JDBC �SQL, Pig�

Bulk Uploader

Embulk,TD Toolbelt

SQL-based query

@AWS or @IDCF

Connectivity

Economy & Flexibility Simple & Supported

Page 9: Fluentd - RubyKansai 65

Dive into…

Page 10: Fluentd - RubyKansai 65

Divide & Conquer & Retry

error retry

error retry retry

retryBatch

Stream

Other stream

Page 11: Fluentd - RubyKansai 65

Application

・・・

Server2

Application

・・・

Server3

Application

・・・

Server1

FluentLog Server

High Latency!must wait for a day...

Before…

Page 12: Fluentd - RubyKansai 65

Application

・・・

Server2

Application

・・・

Server3

Application

・・・

Server1

Fluentd Fluentd Fluentd

Fluentd Fluentd

In streaming!

After…

Page 13: Fluentd - RubyKansai 65

Core Plugins

> Divide & Conquer

> Buffering & Retrying

> Error handling

> Message routing

> Parallelism

> read / receive data > from API, database,

command, etc… > write / send data

> to API, database, alert, graph, etc…

Page 14: Fluentd - RubyKansai 65

Apache to Mongo

tail

insert

event buffering

127.0.0.1 - - [11/Dec/2012:07:26:27] "GET / ... 127.0.0.1 - - [11/Dec/2012:07:26:30] "GET / ... 127.0.0.1 - - [11/Dec/2012:07:26:32] "GET / ... 127.0.0.1 - - [11/Dec/2012:07:26:40] "GET / ... 127.0.0.1 - - [11/Dec/2012:07:27:01] "GET / ...

...

Fluentd

Web Server

2012-02-04 01:33:51 apache.log

{ "host": "127.0.0.1", "method": "GET", ... }

Page 15: Fluentd - RubyKansai 65

> default second unit

> from data source

Event structure(log message)

✓ Time

> for message routing

> where is from?

✓ Tag

> JSON format

> MessagePackinternally

> schema-free

✓ Record

Page 16: Fluentd - RubyKansai 65

Architecture (v0.12 or later)

EngineInput

Filter Output

Buffer

> grep > record_transfomer > …

> Forward > File tail > ...

> Forward > File > ...

Output

> File > Memory

not pluggable

FormatterParser

Page 17: Fluentd - RubyKansai 65

Configuration and operation

> No central / master node > include helps configuration sharing

> Operation depends on your environment > Use your deamon management > Use Chef in Treasure Data

> Apache like syntax and Ruby DSL

Page 18: Fluentd - RubyKansai 65

# receive events via HTTP <source> type http port 8888 </source> !# read logs from a file <source> type tail path /var/log/httpd.log format apache tag apache.access </source> !# save access logs to MongoDB <match apache.access> type mongo database apache collection log </match>

# save alerts to a file <match alert.**> type file path /var/log/fluent/alerts </match> !# forward other logs to servers <match **> type forward <server> host 192.168.0.11 weight 20 </server> <server> host 192.168.0.12 weight 60 </server> </match> !include http://example.com/conf

Page 19: Fluentd - RubyKansai 65

Plugins - use rubygems

$ fluent-gem search -rd fluent-plugin!

!

$ fluent-gem search -rd fluent-mixin!

!

$ fluent-gem install fluent-plugin-mongo

Page 20: Fluentd - RubyKansai 65

in_tail

✓ read a log file!✓ custom regexp!✓ custom parser in Ruby

FluentdApache

access.log

> json > csv > tsv > ltsv

Supported format:> apache > apache_error > apache2 > nginx

> syslog > none

Page 21: Fluentd - RubyKansai 65

out_webhdf

Fluentd

buffer

✓ retry automatically!✓ exponential retry wait!✓ persistent on a file

✓ slice files based on time2013-01-01/01/access.log.gz!2013-01-01/02/access.log.gz!2013-01-01/03/access.log.gz!...

HDFS

✓ custom text formatter

Apache

access.log

Page 22: Fluentd - RubyKansai 65

out_copy

✓ routing based on tags!✓ copy to multiple storages

Amazon S3

Fluentd

buffer

Apache

access.log

Page 23: Fluentd - RubyKansai 65

out_forward

apache

✓ automatic fail-over!✓ load balancing

FluentdApache

bufferaccess.log

✓ retry automatically!✓ exponential retry wait!✓ persistent on a file

Fluentd

Fluentd

Fluentd

Page 24: Fluentd - RubyKansai 65

Before

Page 25: Fluentd - RubyKansai 65

After

or Embulk

Page 26: Fluentd - RubyKansai 65

Nagios

MongoDB

Hadoop

Alerting

Amazon S3

Analysis

Archiving

MySQL

Apache

Frontend

Access logs

syslogd

App logs

System logs

Backend

Databasesbuffering / processing / routing

M x N → M + N

Page 27: Fluentd - RubyKansai 65

Use-cases

Page 28: Fluentd - RubyKansai 65

Treasure Data

FrontendJob Queue

WorkerHadoop

Presto

Fluentd

Applications push metrics to Fluentd (via local Fluentd)

Librato Metricsfor realtime analysis

Treasure Data

for historical analysis

Fluentd sums up data minutes(partial aggregation)

Page 29: Fluentd - RubyKansai 65

hundreds of app servers

sends event logs

sends event logs

sends event logs

Rails app td-agent

td-agent

td-agent

GoogleSpreadsheet

Treasure Data

MySQL

Logs are available

after several mins.

Daily/Hourly

Batch

KPI

visualizationFeedback rankings

Rails app

Rails app

✓ Unlimited scalability✓ Flexible schema✓ Realtime✓ Less performance impact

Cookpad

✓ Over 100 RoR servers (2012/2/4)

Page 30: Fluentd - RubyKansai 65

Slideshare

http://engineering.slideshare.net/2014/04/skynet-project-monitor-scale-and-auto-heal-a-system-in-the-cloud/

Page 31: Fluentd - RubyKansai 65

Log Analysis System And its designs in LINE Corp. 2014 early

Page 32: Fluentd - RubyKansai 65

Roadmap

Page 33: Fluentd - RubyKansai 65

v0.10 (old stable)

> Mainly for log forwarding > with good performance > working in production

> almost users use td-agent > Various plugins

> http://www.fluentd.org/plugins

Page 34: Fluentd - RubyKansai 65

v0.12 (current stable)> Event handling improvement

> Filter > Label > Error Stream

> At-least-once semantics in forwarding > require_ack_response parameter > http://ogibayashi.github.io/blog/2014/12/16/try-

fluentd-v0-dot-12-at-least-once/

Page 35: Fluentd - RubyKansai 65

> Apply filtering routine to event stream > No more tag tricks!

Filter

<match access.**> type record_reformer tag reformed.${tag} </match> !<match reformed.**> type growthforecast </match>

<filter access.**> type record_transformer … </filter>

v0.10: v0.12:

<match access.**> type growthforecast </match>

Page 36: Fluentd - RubyKansai 65

> Internal event routing > Redirect events to another group

> much easier to group and share plugins

Label

<source> type forward </source> !<match app1.**> type record_reformer </match> !…

<source> type forward @label @APP1 </source><label @APP1> <match access.**> type s3 </match> </label>

v0.10: v0.12:

Page 37: Fluentd - RubyKansai 65

Error stream with Label

> Can handle an error at each record level > It is still prototype ERROR!

{"event":1, ...}

{"event":2, ...}

{"event":3, ...}

chunk1

{"event":4, ...}

{"event":5, ...}

{"event":6, ...}

chunk2

Input

OK

ERROR!

OK

OK

OK

Output

<label @ERROR> <match **> type file ... </match> </label>

Error stream

Built-in @ERROR is used when error occurred in “emit”

Page 38: Fluentd - RubyKansai 65

v0.14 (next stable)

> New plugin APIs > Actor > New base classes (#309)

> ServerEngine based core engine > Robust supervisor

> Sub-second time support (#461) > Zero downtime restart

Page 39: Fluentd - RubyKansai 65

Actor> Easy to write popular routines > Hide implementation details

class TimerWatcher < Coolio::TimerWatcher ... end !def start @loop = Coolio::Loop.new @timer = ... @loop.attach(@timer) @thread = ... end

def configure(conf) actor.every(@interval) { router.emit(...) } end !def start actor.start end

v10: v0.14:

Page 40: Fluentd - RubyKansai 65

> Socket manager shared resources with workers

40

SupervisorTCP

1. Listen to TCP socket

Zero downtime restart

Page 41: Fluentd - RubyKansai 65

41

Worker

Supervisor

heartbeat

TCP

TCP

1. Listen to TCP socket

2. Pass its socket to worker

Zero downtime restart

> Socket manager shared resources with workers

Page 42: Fluentd - RubyKansai 65

42

Worker

Supervisor

Worker

TCP

TCP

1. Listen to TCP socket

2. Pass its socket to worker

3. Do same actionat worker restartingwith keeping TCP socket

heartbeat

Zero downtime restart

> Socket manager shared resources with workers

TODO: How to implement on JRuby?

Page 43: Fluentd - RubyKansai 65

v1 (future stable)

> Fix new features / APIs > Plugin APIs > Default configurations

> Clear versioning and stability > No breaking API compatibility!

> Breaking compatibility by Fluentd v2 ?

Page 44: Fluentd - RubyKansai 65

Roadmap summary> v0.10 (old stable) > v0.12 (current stable)

> Filter / Label / At-least-once > v0.14 (spring, 2015)

> New plugin APIs, ServerEngine, Time… > v1 (early summer, 2015)

> Fix new features / APIs

https://github.com/fluent/fluentd/wiki/V1-Roadmap

Page 45: Fluentd - RubyKansai 65

Other TODO

> Windows support > Need feedback! > https://github.com/fluent/fluentd/tree/windows

> Also check: http://qiita.com/okahashi117

> JRuby support > msgpack / cool.io now work on JRuby > https://github.com/fluent/fluentd/issues/317

Page 46: Fluentd - RubyKansai 65

Ecosystem

Page 47: Fluentd - RubyKansai 65

Treasure Agent (td-agent)

> Treasure Data distribution of Fluentd > Treasure Agent 2 is current stable

> Update core components > We recommend to use v2, not v1

> Next version, 2.2.0, uses fluentd v0.12 > In this week or next week

Page 48: Fluentd - RubyKansai 65

fluentd-forwarder> Forwarding agent written in Go

> Focusing log forwarding to Fluentd > Work on Windows

> Bundle TCP input/output and TD output > No flexible plugin mechanizm > We have a plan to add some input/output

> Similar product > fluent-agent-lite, fluent-agent-hydra, ik

Page 49: Fluentd - RubyKansai 65

fluentd-ui

> Manage Fluentd instance via Web UI > https://github.com/fluent/fluentd-ui

Page 50: Fluentd - RubyKansai 65

Embulk

> Bulk Loader version of Fluentd > Pluggable architecture

> JRuby, JVM languages > High performance parallel processing

> Share your script as a plugin > https://github.com/embulk

http://www.slideshare.net/frsyuki/embuk-making-data-integration-works-relaxed

Page 51: Fluentd - RubyKansai 65

HDFS

MySQL

Amazon S3

Embulk

CSV Files

SequenceFile

Salesforce.com

Elasticsearch

Cassandra

Hive

Redis

✓ Parallel execution ✓ Data validation ✓ Error recovery ✓ Deterministic behaviour ✓ Idempotent retrying

Plugins Plugins

bulk load

Page 52: Fluentd - RubyKansai 65

Check: treasuredata.comCloud service for the entire data pipeline