Fluentd and docker monitoring

45
FluentD and Docker Vinay Krishna SolutionsIQ

Transcript of Fluentd and docker monitoring

Page 1: Fluentd and docker monitoring

FluentD and DockerVinay Krishna

SolutionsIQ

Page 2: Fluentd and docker monitoring

Monitoring

Page 3: Fluentd and docker monitoring

Is it simple?

• Monitoring

• Applications

• Servers

Page 4: Fluentd and docker monitoring
Page 5: Fluentd and docker monitoring

Logging

Page 6: Fluentd and docker monitoring

What?

• Status of application

• Keeps information about errors/failure

• Status of Network

Page 7: Fluentd and docker monitoring

Why?

• Developers• Get help in Debugging

• IT admin / support • Get help in Trouble-shooting• Apps running smoothly• Security

• Business• Input data – analytics• User interaction / behaviors• Improvements

Page 8: Fluentd and docker monitoring

Assumptions

• I have enough disk space

• I/O operations will not block

• Log messages are human readable

• My logging mechanism scale

• Basically, yeah.. it should work.

Page 9: Fluentd and docker monitoring

Concerns

• Logs increase = data increase

• Message format get more complex

• Did the Kernel flush the buffers ? (sync(2))

• Multi-thread application ?, locking ?

• Multiple Applications = Multiple Logs

• If Multiple Applications = Multiple logs

• Multiple Hosts x Multiple Applications = ???

Page 10: Fluentd and docker monitoring

How to parse/store multiple data sources ?

Page 11: Fluentd and docker monitoring

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

It allows you to unify data collection and consumption for a better use and understanding of data.

• Structured logging

• Reliable forwarding

• Pluggable architecture

Page 12: Fluentd and docker monitoring

Fluentd

• Data collection for unified logging layer• Streaming data transfer based on JSON

• Written in Ruby

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

• Working on lots of productions• http://www/fluentd.org/testimonials

Page 13: Fluentd and docker monitoring

Before

Page 14: Fluentd and docker monitoring

After

Page 15: Fluentd and docker monitoring
Page 16: Fluentd and docker monitoring

Highlights

• Unified Logging Layer• Fluentd tries to structure data as JSON as much as possible

• Simple and yet flexible• 300+ plugins

• Open Source

• Proven Reliability and Performance• 2000+ data-driven companies rely on FluentD• Minimum resources required - vanilla instance runs on 30-40MB of

memory and can process 13,000 events/second/core• Data loss should never happen. • Fluentd supports memory- and file-based buffering to prevent inter-node

data loss. • Fluentd also supports robust failover and can be set up for high availability

• Community

Page 17: Fluentd and docker monitoring
Page 18: Fluentd and docker monitoring

Docker Monitoring

Page 19: Fluentd and docker monitoring

Monitor

• Resource utilization• How much RAM and CPU is each container using?

• Health of docker environments

• As the Docker ecosystem continues to evolve, we have to ask ourselves the following questions:

• How can we log and monitor Docker effectively? • This includes logging the Docker runtime infrastructure, the container itself and

what goes on inside of it, and how to ensure to collect log data from ephemeral containers.

• How can we use feedback from containers to manage and improve the quality of our services?

• Can we build off of decades of experience logging monolithic applications, or do we have to start from scratch?

• If we have to start from scratch, how can we build a solution that helps us make better decisions?

Page 20: Fluentd and docker monitoring

FluentD + Docker

Page 21: Fluentd and docker monitoring

Logging of container architecture

• Storage: • should be outside of container / hosts

• Transferring: • should be over network

• Aggregation: • should be done per container / per service

Page 22: Fluentd and docker monitoring

FluentD Architecture

Page 23: Fluentd and docker monitoring
Page 24: Fluentd and docker monitoring
Page 25: Fluentd and docker monitoring
Page 26: Fluentd and docker monitoring
Page 27: Fluentd and docker monitoring
Page 28: Fluentd and docker monitoring
Page 29: Fluentd and docker monitoring
Page 30: Fluentd and docker monitoring

Logging Driver

• Docker v1.6 released the concept of logging drivers

• Route container output

• Add new logging driver – fluentd• --log-driver=fluentd

• https://github.com/docker/docker/pull/12876

• New for docker v1.7.0?

Page 31: Fluentd and docker monitoring

Container logging driver “fluentd”

• Apps write logs to STDOUT:• docker sends it to fluentd

directly!

• Pros:• simple conf for apps and

docker• logs include container logs

• Cons:• ?

Page 32: Fluentd and docker monitoring

Fluentd docker image

• Official image by fluentd organization

https://registry.hub.docker.com/u/fluent/fluentd/

• Use it as it is, or build your own container!

https://github.com/fluent/fluentd-docker-image

Page 33: Fluentd and docker monitoring

Demo

Page 34: Fluentd and docker monitoring

Install fluentd

• Install fluentd via td-agent

curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-trusty-td-agent2.sh | sh

• Start td-agent

sudo /etc/init.d/td-agent start

Page 35: Fluentd and docker monitoring

Verify installation

• Check the logs to make sure it was installed successfully• tail /var/log/td-agent/td-agent.log

Page 36: Fluentd and docker monitoring

Build fluentd image

• Create a new directory for your Fluentd Docker resources, and move into it• mkdir ~/fluentd-docker && cd ~/fluentd-docker

• Create the following Dockerfile• sudo nano Dockerfile

• Add the following content:

FROM ruby:2.2.0

MAINTAINER [email protected]

RUN apt-get update

RUN gem install fluentd -v "~>0.12.3"

RUN mkdir /etc/fluent

RUN apt-get install -y libcurl4-gnutls-dev make

RUN /usr/local/bin/gem install fluent-plugin-elasticsearch

ADD fluent.conf /etc/fluent/

ENTRYPOINT ["/usr/local/bundle/bin/fluentd", "-c", "/etc/fluent/fluent.conf"]

Page 37: Fluentd and docker monitoring

Build fluentd image

• Create a fluent.conf file in the same directory• sudo nano fluent.conf

Page 38: Fluentd and docker monitoring

<source>

type tail

read_from_head true

path /var/lib/docker/containers/*/*-json.log

pos_file /var/log/fluentd-docker.pos

time_format %Y-%m-%dT%H:%M:%S

tag docker.*

format json

</source>

# Using filter to add container IDs to each event

<filter docker.var.lib.docker.containers.*.*.log>

type record_transformer

<record>

container_id ${tag_parts[5]}

</record>

</filter>

<match docker.var.lib.docker.containers.*.*.log>

type elasticsearch

logstash_format true

host "#{ENV['ES_PORT_9200_TCP_ADDR']}" # dynamically configured to use Docker's link feature

port 9200

flush_interval 5s

</match>

Page 39: Fluentd and docker monitoring

• Build docker image• docker build -t fluentd-es .

• Check successfully built the images• docker images

Page 40: Fluentd and docker monitoring

ElasticSearch Container

• Move to home directory• Cd ~

• Download and start the Elasticsearch container• docker run -d -p 9200:9200 -p 9300:9300 --name es

elasticsearch

• Check elasticsearch container is running• docker ps

Page 41: Fluentd and docker monitoring

Start the Fluentd-to-ElasticsearchContainer• Start the container that runs Fluentd, collects the

logs, and sends them to Elastcisearch• docker run -d --link es:es -v

/var/lib/docker/containers:/var/lib/docker/containers fluentd-es

• Check that container is running• docker ps

Page 42: Fluentd and docker monitoring

Confirm ElasticSearch receives events• curl -XGET 'http://localhost:9200/_all/_search?q=*‘

Page 43: Fluentd and docker monitoring

What’s next

• Setup Dashboard

Page 44: Fluentd and docker monitoring

References

• http://www.fluentd.org/guides/recipes/docker-logging

• http://www.slideshare.net/repeatedly/docker-and-fluentd-51821582

• http://www.slideshare.net/tagomoris/docker-and-fluentd-revised

• https://www.socallinuxexpo.org/sites/default/files/presentations/fluentd.pdf

Page 45: Fluentd and docker monitoring

Questions?