SlideShare uma empresa Scribd logo
1 de 57
Building a Unified Logging Layer with
Fluentd, Elasticsearch and Kibana
Mushfekur Rahman
What This Session is About
● What is Unified Logging Layer?
● Why We Need One?
● Basics of Fluentd
● Storage and Querying Using Elasticsearch
● Real Time Visualization with Kibana
Unified Logging Layer
Unified Logging Layer (cont.)
Unified Logging Layer (cont.)
We need something that can-
● Collect logs from multiple sources
● Can format and/or filter those according to our need
● Forward them to appropriate destinations for storage or
analysis
Unified Logging Layer (cont.)
Fluentd
#MomentOfTruth
Basics of Fluentd
● Fluentd is a stream data collector application but it can work as a-
○ Filter
○ Buffer
○ Router
○ Converter
○ Aggregator etc etc.
● But it doesn’t come with these features built-in
● Instead, it has a flexible plugin based architecture consisting of
three modules: input, buffer and output. So everything is a plugin in
Fluentd-land (like LEGO blocks)
Why Fluentd?
● Open source
○ Github: https://github.com/fluent/fluentd
○ Developed and maintained by Treasure Data, Inc.
● Reliable
○ Buffering
■ Supports memory and file based buffering to prevent data loss when
routing between nodes
○ Retrying
■ Includes mechanism for retrying if there’s any failure to capture an
event
■ Uses buffer ID for maintaining idempotency
○ Error handling
■ Forward plugin has support for load balancing, transaction, failover
etc
■ Supports secondary node for backup and/or load balancing
Why Fluentd? (cont.)
● Scalable and easy to extend
○ Completely decentralized architecture (e.g. no central/master node)
hence easy to scale-out
○ Plugins to communicate between nodes
● Rich plugin ecosystem based on rubygems
○ 300+ community plugins
○ Easy apache-like configuration syntax with Ruby DSL support
● Uses minimum resource
○ Developed using CRuby (performance critical sections are written in C
while plugins are developed in Ruby)
○ Vanilla instance uses only 30-40 MB of memory
○ Can process up to 1300 events/sec/core
Fluentd Architecture
Fluentd Architecture (cont.)
● Input
○ Event
● Output
○ Non-buffered
○ Buffered
○ Time sliced buffered
● Buffer
○ Memory
○ File
Fluentd Events
● Time
○ Uses timestamp to order events
○ Network should have NTP (Network Time Protocol) configured
● Tag
○ For routing
● Record
○ The actual log message
○ Usually JSON
Capturing Events
● File tailing
○ Uses in_tail plugin
○ Allows reading events from the tail of text files
○ Keeps track of inode number so handles rotations
● Directly from application
○ Use Fluentd Logger
■ For Java: https://github.com/fluent/fluent-logger-java
○ Use Logback Fluentd appender
■ https://github.com/sndyuk/logback-more-appenders
● From other interfaces like
○ TCP/UDP, Socket, Stdout, syslog etc.
Fluentd Output
● Capable of forwarding events to almost all mainstream
interfaces like Stdout, Socket, /dev/null etc
● There is plugin for most of the popular storage or
analytics engine like Amazon S3, Elasticsearch, TD
Analytics Cloud, Mongo DB, Hadoop HDFS etc.
● Can send alerts using SMTP plugin
● Outputs can be both buffered and non-buffered
● Can even route an event to itself
○ Filtering, conversion and/or formatting
Fluentd Buffering
Plugin Management
● 6 types of plugin in total: Input, Parser, Formatter, Filter,
Output and Buffer
● Using td-agent
○ To install plugin
/usr/sbin/td-agent-gem install fluent-plugin-
<name>
● Fluentd will pick up any plugin in its LOAD_PATH
● To add any plugin that’s not in default load path
fluentd -p path/to/plugins
Running Fluentd
● Can be installed using td-agent and/or ruby gems
● Configuration file in
/etc/td-agent/td-agent.conf
● OS X
$ sudo launchctl unload /Library/LaunchDaemons/td-agent.plist
$ sudo launchctl load /Library/LaunchDaemons/td-agent.plist
● Linux
$ sudo /etc/init.d/td-agent restart
Sample Config
Input
<source>
type tail
format apache
path path/to/log/file
pos_file path/to/pos
tag apache.access
</source>
Output
<match apache.**>
type copy
<store>
type elasticsearch
host <host>
port <port>
<store>
path /path/to/file/buffer
</match>
High Availability Config
Two types of nodes:
1. Forwarders
○ Typically installed on every node to capture local events
○ Next they forward those events to aggregators through network (TCP)
2. Aggregators
○ Daemons that receive events from forwarders
○ Later they upload these events to analytics engine or storage for
further processing
High Availability Config (cont.)
Email Alerting
● Grep for patterns in log and send Email alert when
certain conditions are met
● Saves your inbox from getting flooded with alert mails
● Like Grep-and-Alert-Email of Splunk
● Need to install two plugins
■ fluent-plugin-grepcounter
■ fluent-plugin-mail
● Sample configuration: Gist
Fluentd Failure Scenarios
● We cannot get past to the Murphy’s Law
● Upon receiving an event, a fluentd instance (forwarder or
aggregator) writes it to the buffer (specified by
buffer_path for disks) and after a flush_interval
buffered events are forwarded to the aggregator
● If an instance dies, buffered data is transferred on restart
○ Instances are restarted automatically
● If the connection from an instance breaks, a retry event is
triggered
Fluentd Failure Scenarios (cont.)
● Disk buffering is inherently robust against
data loss, however data will be lost if-
○ An instance dies right after receiving an event but
before writing it to the disk
○ The disk breaks and data buffer is lost
Performance Tuning
● If there’s any CPU bottleneck in the system we can
utilize multiple cores using in_multiprocess plugin
● Setup ntpd to prevent invalid log timestamps
● Increase the maximum number of file descriptor to
65535
● If you’re directly pushing logs from application to
Fluentd via TCP then enable tcp_tw_recycle and
tcp_tw_reuse to cope with TCP TIME-WAIT.
Who Uses Fluentd
● Over 20K companies
Elasticsearch
Elasticsearch
● An open source, flexible, powerful, distributed, real time text search
engine
● Built on top of Apache Lucene
● Runs on JVM
● Second most popular enterprise search engine on the planet
○ New kid in the block
○ First official release in 2010
● Developed by Shay Banon and currently maintained by
ElasticSearch
○ Github: https://github.com/elastic/elasticsearch
Why Elasticsearch?
● Real time write and analytics
○ Blazing fast indexing
● Long term persistence
○ Writes data to the filesystem
● NoSQL based document storage (like MongoDB)
● Schema free and denormalized (JSON in, JSON out)
● Full text search
○ Search from large volume of unstructured text data
Why Elasticsearch? (cont.)
● Distributed
○ Supports horizontal scaling out of the box
○ Automatic node discovery and sharding
● Multi tenant architecture
○ A single node can contain multiple indices and can
be queried individually or as a group
● High availability
○ Resilient cluster management which automatically
detects node failure and rebalances data
Why Elasticsearch? (cont.)
● Robust conflict management to prevent data loss
○ Uses optimistic concurrency control and versioning
● RESTful API hence developer friendly
○ Easy to perform an operation from application or any
CLI tools (e.g. curl)
ES Terminology
ES Terminology (cont.)
● Shard
○ A lucene index
○ Replicated to ensure data availability
○ Each ES index contains one or more primary shards
● Node
○ A running ES instance
● Cluster
○ Collection of cooperating ES nodes
○ Manages nodes to have better availability and performance
● So the hierarchy is-
Cluster > Node > Index > Shard > Document > Field
ES Up and Running
● Settings
○ Config file
<ES_HOME>/config/elasticsearch.yml
○ Default node name is a Marvel comics character
○ Configurations can be changed using configuration file or can be
passed as a JVM arg during startup
● To start an ES instance
$ <ES_HOME>/bin/elasticsearch --cluster.name=<name>
● Can be accessed from
http://localhost:9200
ES Query DSL
● Endpoint
○ Refers to ES index type
○ Can contain multiple indices and types (Remember multitenancy?)
● Query types
○ Basic query using query parameters
{endpoint}/_search?q=code:304&size=10&pretty=true
○ Using query object
curl -XPOST {endpoint} -d ‘{json_query_doc}’
ES Query DSL (cont.)
● Basic ES JSON query format
{
size: # number of results (default 10),
from: # offset into results (default 0),
sort: # sort order,
query: # query object,
facet: # meta information about a field,
filter: # filter results on a specific value or range
}
ES Query DSL (cont.)
● Basic ES response format
{
# the results
hits: {
total: # total number of matched documents
hits: [
_id: # id of the document
max_score: # search index score (relevance with the search query)
_source: {} # the actual JSON document which was indexed
],
},
facets: {}
}
ES Query DSL (cont.)
● Examples
○ Match all
{"query": {
"match_all": {}
}}
○ Classic full text query
{"query": {
"query_string": {
"query": "shuttle/countdown/liftoff.html"
}
}}
ES Query DSL (cont.)
○ Filter on a field
{"query": {
"term": {
{field-name}: {value}
}
}}
ES Query DSL (cont.)
○ Range query (number, date etc.)
{"query": {
"constant_score": {
"filter": {
"range": {
{field-name}: {
"from": {lower-value}
"to": {upper-value}
}}
}}
}
}
ES Query DSL (cont.)
● Writing optimized query
○ Always use filters
{"query": {
"filtered" : {
"query" : {
/* query fields */
},
"filter" : {
/* filters */
}
}
}}
ES Performance Tuning
● Increase the number of open file descriptors from 32K
to even 64K
● ES is designed to function well while running on multiple
commodity machines rather than a single machine
○ Make a cluster with several nodes if you have
staggering amount of text
○ Find a sweet spot for your shard size which suites
best with your system
● Don’t let ES to consume all memory
○ Frequently accessed part of the index is assumed to be
in OS page cache
○ Search filters can also be cached in filter cache to
provide fast response
○ Field values are used for faceting and cached into field
cache
○ Keep track of memory stats so that OutOfMemory never
happens
○ Xms and Xmx should be equal
ES Performance Tuning (cont.)
ES Performance Tuning (cont.)
● Client considerations
○ Idempotent request
■ Requests that may change server state should
be idempotent
○ Connection pooling
■ Avoid creating a request for every query
○ Bulk update request
■ Can request bulk update when needed
■ Catch: No rollback if operation fails during update
ES Users
Haaave you met?
● Highly customizable dashboarding
● Kibana 3
○ Just a front-end (Angular.js + jQuery + Elastic.js)
● Kibana 4
○ Standalone web application
○ Node.js
○ Float (jQuery plotting library)
● Developed and maintained by ElasticSearch as a part
of ELK Stack
● Github: https://github.com/elastic/kibana
Kibana
Why Kibana?
● Built to work with Elasticsearch
● Gives shapes to data
● Very flexible interface
● Easy to export data
● Easy setup procedure
Kibana Setup
● Configuration
○ Config file
<KIBANA_HOME>/config/kibana.yml
● To start Kibana
<KIBANA_HOME>/bin/kibana
● Access
http://localhost:5601
● Settings
○ Tell Kibana from where to pull data
○ Configure an index pattern
● Discover
○ Displays all available documents from the search
result based on a specific timespan
○ Visualizes available data using histogram
○ Search using Lucene Query Syntax
Kibana Navigation
Kibana Navigation (cont.)
● Visualize
○ Creates visualizations like area chart, pie chart, data
table, tile map etc using appropriate data
● Dashboard
○ Several visualizations can be placed in a dashboard
○ Dashboard can have data from multiple indices
○ Saves you from creating frequently needed
visualizations over and over again
Kibana Access Control
● No authentication or role based dashboard access
support out of the box
● Basic authentication can be done from a proxy server
(e.g. nginx)
● Use Shield by ElasticSearch
○ Authentication services for both ES and Kibana
○ Role based access control for both ES and Kibana
○ Easy to integrate with OAuth, LDAP
○ Audit logging with complete record of user and system activities
○ Easy SSL/TLS configuration
To Wrap It Up...
How About A Demo?
● Two months worth of HTTP access logs of
NASA Kennedy Space Center of Florida
(openly accessible from here)
● More than 3 million requests from various
sources
● Around 400 MB server log dump
To Explore More...
● Fluentd Documentation
http://docs.fluentd.org/articles/quickstart
● Elasticsearch Reference
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
● Elasticsearch from the bottom up series
https://www.elastic.co/blog/found-elasticsearch-from-the-bottom-up
● Kibana User Guide
https://www.elastic.co/guide/en/kibana/current/index.html
Q&A Time!
?
That’ll be it!
Thanks :)

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar PradhanAwesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
Awesome Traefik - Ingress Controller for Kubernetes - Swapnasagar Pradhan
 
Unlocking the Power of Lakehouse Architectures with Apache Pulsar and Apache ...
Unlocking the Power of Lakehouse Architectures with Apache Pulsar and Apache ...Unlocking the Power of Lakehouse Architectures with Apache Pulsar and Apache ...
Unlocking the Power of Lakehouse Architectures with Apache Pulsar and Apache ...
 
Airflow at lyft
Airflow at lyftAirflow at lyft
Airflow at lyft
 
Airflow introduction
Airflow introductionAirflow introduction
Airflow introduction
 
Introduction to gRPC
Introduction to gRPCIntroduction to gRPC
Introduction to gRPC
 
golang과 websocket을 활용한 서버프로그래밍 - 장애없는 서버 런칭 도전기
golang과 websocket을 활용한 서버프로그래밍 - 장애없는 서버 런칭 도전기golang과 websocket을 활용한 서버프로그래밍 - 장애없는 서버 런칭 도전기
golang과 websocket을 활용한 서버프로그래밍 - 장애없는 서버 런칭 도전기
 
Apache airflow
Apache airflowApache airflow
Apache airflow
 
Evening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in FlinkEvening out the uneven: dealing with skew in Flink
Evening out the uneven: dealing with skew in Flink
 
Building your First gRPC Service
Building your First gRPC ServiceBuilding your First gRPC Service
Building your First gRPC Service
 
Introduction to Spark Streaming
Introduction to Spark StreamingIntroduction to Spark Streaming
Introduction to Spark Streaming
 
Apache Flink internals
Apache Flink internalsApache Flink internals
Apache Flink internals
 
Airflow for Beginners
Airflow for BeginnersAirflow for Beginners
Airflow for Beginners
 
Fluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshellFluentd v1.0 in a nutshell
Fluentd v1.0 in a nutshell
 
Prometheus and Grafana
Prometheus and GrafanaPrometheus and Grafana
Prometheus and Grafana
 
Introduction to Open Telemetry as Observability Library
Introduction to Open  Telemetry as Observability LibraryIntroduction to Open  Telemetry as Observability Library
Introduction to Open Telemetry as Observability Library
 
Apache airflow
Apache airflowApache airflow
Apache airflow
 
Airflow presentation
Airflow presentationAirflow presentation
Airflow presentation
 
Monitoring Kubernetes with Prometheus
Monitoring Kubernetes with PrometheusMonitoring Kubernetes with Prometheus
Monitoring Kubernetes with Prometheus
 
Introduction to Apache Spark
Introduction to Apache SparkIntroduction to Apache Spark
Introduction to Apache Spark
 
Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...Best Practices for Middleware and Integration Architecture Modernization with...
Best Practices for Middleware and Integration Architecture Modernization with...
 

Semelhante a Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana

Initial presentation of swift (for montreal user group)
Initial presentation of swift (for montreal user group)Initial presentation of swift (for montreal user group)
Initial presentation of swift (for montreal user group)
Marcos García
 

Semelhante a Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana (20)

Ledingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @LendingkartLedingkart Meetup #2: Scaling Search @Lendingkart
Ledingkart Meetup #2: Scaling Search @Lendingkart
 
OpenSearch.pdf
OpenSearch.pdfOpenSearch.pdf
OpenSearch.pdf
 
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json  postgre-sql vs. mongodbPGConf APAC 2018 - High performance json  postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
 
Concurrency, Parallelism And IO
Concurrency,  Parallelism And IOConcurrency,  Parallelism And IO
Concurrency, Parallelism And IO
 
Initial presentation of swift (for montreal user group)
Initial presentation of swift (for montreal user group)Initial presentation of swift (for montreal user group)
Initial presentation of swift (for montreal user group)
 
AWS Big Data Demystified #1: Big data architecture lessons learned
AWS Big Data Demystified #1: Big data architecture lessons learned AWS Big Data Demystified #1: Big data architecture lessons learned
AWS Big Data Demystified #1: Big data architecture lessons learned
 
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
Eko10 - Security Monitoring for Big Infrastructures without a Million Dollar ...
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
Journey through high performance django application
Journey through high performance django applicationJourney through high performance django application
Journey through high performance django application
 
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
AWS big-data-demystified #1.1  | Big Data Architecture Lessons Learned | EnglishAWS big-data-demystified #1.1  | Big Data Architecture Lessons Learned | English
AWS big-data-demystified #1.1 | Big Data Architecture Lessons Learned | English
 
Collect distributed application logging using fluentd (EFK stack)
Collect distributed application logging using fluentd (EFK stack)Collect distributed application logging using fluentd (EFK stack)
Collect distributed application logging using fluentd (EFK stack)
 
Node.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scaleNode.js Web Apps @ ebay scale
Node.js Web Apps @ ebay scale
 
Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2Netflix Open Source Meetup Season 4 Episode 2
Netflix Open Source Meetup Season 4 Episode 2
 
Handout: 'Open Source Tools & Resources'
Handout: 'Open Source Tools & Resources'Handout: 'Open Source Tools & Resources'
Handout: 'Open Source Tools & Resources'
 
Log Management: AtlSecCon2015
Log Management: AtlSecCon2015Log Management: AtlSecCon2015
Log Management: AtlSecCon2015
 
Real-time analytics with Druid at Appsflyer
Real-time analytics with Druid at AppsflyerReal-time analytics with Druid at Appsflyer
Real-time analytics with Druid at Appsflyer
 
Distributed real time stream processing- why and how
Distributed real time stream processing- why and howDistributed real time stream processing- why and how
Distributed real time stream processing- why and how
 
Logging for Containers
Logging for ContainersLogging for Containers
Logging for Containers
 
PostgreSQL and Sphinx pgcon 2013
PostgreSQL and Sphinx   pgcon 2013PostgreSQL and Sphinx   pgcon 2013
PostgreSQL and Sphinx pgcon 2013
 

Mais de Mushfekur Rahman (7)

An Automatic Method for Red-eye Detection and Correction in Digital Images
An Automatic Method for Red-eye Detection and Correction in Digital ImagesAn Automatic Method for Red-eye Detection and Correction in Digital Images
An Automatic Method for Red-eye Detection and Correction in Digital Images
 
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMCDiagnosing HotSpot JVM Memory Leaks with JFR and JMC
Diagnosing HotSpot JVM Memory Leaks with JFR and JMC
 
Webservices: The RESTful Approach
Webservices: The RESTful ApproachWebservices: The RESTful Approach
Webservices: The RESTful Approach
 
Http Basics
Http BasicsHttp Basics
Http Basics
 
Hands on Gradle
Hands on GradleHands on Gradle
Hands on Gradle
 
Distributed Transaction Management in Spring & JEE
Distributed Transaction Management in Spring & JEEDistributed Transaction Management in Spring & JEE
Distributed Transaction Management in Spring & JEE
 
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...Implementation of Election Algorithm of Distributed Systems in Client-Server ...
Implementation of Election Algorithm of Distributed Systems in Client-Server ...
 

Último

%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 

Último (20)

MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 

Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana

  • 1. Building a Unified Logging Layer with Fluentd, Elasticsearch and Kibana Mushfekur Rahman
  • 2. What This Session is About ● What is Unified Logging Layer? ● Why We Need One? ● Basics of Fluentd ● Storage and Querying Using Elasticsearch ● Real Time Visualization with Kibana
  • 5. Unified Logging Layer (cont.) We need something that can- ● Collect logs from multiple sources ● Can format and/or filter those according to our need ● Forward them to appropriate destinations for storage or analysis
  • 8. Basics of Fluentd ● Fluentd is a stream data collector application but it can work as a- ○ Filter ○ Buffer ○ Router ○ Converter ○ Aggregator etc etc. ● But it doesn’t come with these features built-in ● Instead, it has a flexible plugin based architecture consisting of three modules: input, buffer and output. So everything is a plugin in Fluentd-land (like LEGO blocks)
  • 9. Why Fluentd? ● Open source ○ Github: https://github.com/fluent/fluentd ○ Developed and maintained by Treasure Data, Inc. ● Reliable ○ Buffering ■ Supports memory and file based buffering to prevent data loss when routing between nodes ○ Retrying ■ Includes mechanism for retrying if there’s any failure to capture an event ■ Uses buffer ID for maintaining idempotency ○ Error handling ■ Forward plugin has support for load balancing, transaction, failover etc ■ Supports secondary node for backup and/or load balancing
  • 10. Why Fluentd? (cont.) ● Scalable and easy to extend ○ Completely decentralized architecture (e.g. no central/master node) hence easy to scale-out ○ Plugins to communicate between nodes ● Rich plugin ecosystem based on rubygems ○ 300+ community plugins ○ Easy apache-like configuration syntax with Ruby DSL support ● Uses minimum resource ○ Developed using CRuby (performance critical sections are written in C while plugins are developed in Ruby) ○ Vanilla instance uses only 30-40 MB of memory ○ Can process up to 1300 events/sec/core
  • 12. Fluentd Architecture (cont.) ● Input ○ Event ● Output ○ Non-buffered ○ Buffered ○ Time sliced buffered ● Buffer ○ Memory ○ File
  • 13. Fluentd Events ● Time ○ Uses timestamp to order events ○ Network should have NTP (Network Time Protocol) configured ● Tag ○ For routing ● Record ○ The actual log message ○ Usually JSON
  • 14. Capturing Events ● File tailing ○ Uses in_tail plugin ○ Allows reading events from the tail of text files ○ Keeps track of inode number so handles rotations ● Directly from application ○ Use Fluentd Logger ■ For Java: https://github.com/fluent/fluent-logger-java ○ Use Logback Fluentd appender ■ https://github.com/sndyuk/logback-more-appenders ● From other interfaces like ○ TCP/UDP, Socket, Stdout, syslog etc.
  • 15. Fluentd Output ● Capable of forwarding events to almost all mainstream interfaces like Stdout, Socket, /dev/null etc ● There is plugin for most of the popular storage or analytics engine like Amazon S3, Elasticsearch, TD Analytics Cloud, Mongo DB, Hadoop HDFS etc. ● Can send alerts using SMTP plugin ● Outputs can be both buffered and non-buffered ● Can even route an event to itself ○ Filtering, conversion and/or formatting
  • 17. Plugin Management ● 6 types of plugin in total: Input, Parser, Formatter, Filter, Output and Buffer ● Using td-agent ○ To install plugin /usr/sbin/td-agent-gem install fluent-plugin- <name> ● Fluentd will pick up any plugin in its LOAD_PATH ● To add any plugin that’s not in default load path fluentd -p path/to/plugins
  • 18. Running Fluentd ● Can be installed using td-agent and/or ruby gems ● Configuration file in /etc/td-agent/td-agent.conf ● OS X $ sudo launchctl unload /Library/LaunchDaemons/td-agent.plist $ sudo launchctl load /Library/LaunchDaemons/td-agent.plist ● Linux $ sudo /etc/init.d/td-agent restart
  • 19. Sample Config Input <source> type tail format apache path path/to/log/file pos_file path/to/pos tag apache.access </source> Output <match apache.**> type copy <store> type elasticsearch host <host> port <port> <store> path /path/to/file/buffer </match>
  • 20. High Availability Config Two types of nodes: 1. Forwarders ○ Typically installed on every node to capture local events ○ Next they forward those events to aggregators through network (TCP) 2. Aggregators ○ Daemons that receive events from forwarders ○ Later they upload these events to analytics engine or storage for further processing
  • 22. Email Alerting ● Grep for patterns in log and send Email alert when certain conditions are met ● Saves your inbox from getting flooded with alert mails ● Like Grep-and-Alert-Email of Splunk ● Need to install two plugins ■ fluent-plugin-grepcounter ■ fluent-plugin-mail ● Sample configuration: Gist
  • 23. Fluentd Failure Scenarios ● We cannot get past to the Murphy’s Law ● Upon receiving an event, a fluentd instance (forwarder or aggregator) writes it to the buffer (specified by buffer_path for disks) and after a flush_interval buffered events are forwarded to the aggregator ● If an instance dies, buffered data is transferred on restart ○ Instances are restarted automatically ● If the connection from an instance breaks, a retry event is triggered
  • 24. Fluentd Failure Scenarios (cont.) ● Disk buffering is inherently robust against data loss, however data will be lost if- ○ An instance dies right after receiving an event but before writing it to the disk ○ The disk breaks and data buffer is lost
  • 25. Performance Tuning ● If there’s any CPU bottleneck in the system we can utilize multiple cores using in_multiprocess plugin ● Setup ntpd to prevent invalid log timestamps ● Increase the maximum number of file descriptor to 65535 ● If you’re directly pushing logs from application to Fluentd via TCP then enable tcp_tw_recycle and tcp_tw_reuse to cope with TCP TIME-WAIT.
  • 26. Who Uses Fluentd ● Over 20K companies
  • 28. Elasticsearch ● An open source, flexible, powerful, distributed, real time text search engine ● Built on top of Apache Lucene ● Runs on JVM ● Second most popular enterprise search engine on the planet ○ New kid in the block ○ First official release in 2010 ● Developed by Shay Banon and currently maintained by ElasticSearch ○ Github: https://github.com/elastic/elasticsearch
  • 29. Why Elasticsearch? ● Real time write and analytics ○ Blazing fast indexing ● Long term persistence ○ Writes data to the filesystem ● NoSQL based document storage (like MongoDB) ● Schema free and denormalized (JSON in, JSON out) ● Full text search ○ Search from large volume of unstructured text data
  • 30. Why Elasticsearch? (cont.) ● Distributed ○ Supports horizontal scaling out of the box ○ Automatic node discovery and sharding ● Multi tenant architecture ○ A single node can contain multiple indices and can be queried individually or as a group ● High availability ○ Resilient cluster management which automatically detects node failure and rebalances data
  • 31. Why Elasticsearch? (cont.) ● Robust conflict management to prevent data loss ○ Uses optimistic concurrency control and versioning ● RESTful API hence developer friendly ○ Easy to perform an operation from application or any CLI tools (e.g. curl)
  • 33. ES Terminology (cont.) ● Shard ○ A lucene index ○ Replicated to ensure data availability ○ Each ES index contains one or more primary shards ● Node ○ A running ES instance ● Cluster ○ Collection of cooperating ES nodes ○ Manages nodes to have better availability and performance ● So the hierarchy is- Cluster > Node > Index > Shard > Document > Field
  • 34. ES Up and Running ● Settings ○ Config file <ES_HOME>/config/elasticsearch.yml ○ Default node name is a Marvel comics character ○ Configurations can be changed using configuration file or can be passed as a JVM arg during startup ● To start an ES instance $ <ES_HOME>/bin/elasticsearch --cluster.name=<name> ● Can be accessed from http://localhost:9200
  • 35. ES Query DSL ● Endpoint ○ Refers to ES index type ○ Can contain multiple indices and types (Remember multitenancy?) ● Query types ○ Basic query using query parameters {endpoint}/_search?q=code:304&size=10&pretty=true ○ Using query object curl -XPOST {endpoint} -d ‘{json_query_doc}’
  • 36. ES Query DSL (cont.) ● Basic ES JSON query format { size: # number of results (default 10), from: # offset into results (default 0), sort: # sort order, query: # query object, facet: # meta information about a field, filter: # filter results on a specific value or range }
  • 37. ES Query DSL (cont.) ● Basic ES response format { # the results hits: { total: # total number of matched documents hits: [ _id: # id of the document max_score: # search index score (relevance with the search query) _source: {} # the actual JSON document which was indexed ], }, facets: {} }
  • 38. ES Query DSL (cont.) ● Examples ○ Match all {"query": { "match_all": {} }} ○ Classic full text query {"query": { "query_string": { "query": "shuttle/countdown/liftoff.html" } }}
  • 39. ES Query DSL (cont.) ○ Filter on a field {"query": { "term": { {field-name}: {value} } }}
  • 40. ES Query DSL (cont.) ○ Range query (number, date etc.) {"query": { "constant_score": { "filter": { "range": { {field-name}: { "from": {lower-value} "to": {upper-value} }} }} } }
  • 41. ES Query DSL (cont.) ● Writing optimized query ○ Always use filters {"query": { "filtered" : { "query" : { /* query fields */ }, "filter" : { /* filters */ } } }}
  • 42. ES Performance Tuning ● Increase the number of open file descriptors from 32K to even 64K ● ES is designed to function well while running on multiple commodity machines rather than a single machine ○ Make a cluster with several nodes if you have staggering amount of text ○ Find a sweet spot for your shard size which suites best with your system
  • 43. ● Don’t let ES to consume all memory ○ Frequently accessed part of the index is assumed to be in OS page cache ○ Search filters can also be cached in filter cache to provide fast response ○ Field values are used for faceting and cached into field cache ○ Keep track of memory stats so that OutOfMemory never happens ○ Xms and Xmx should be equal ES Performance Tuning (cont.)
  • 44. ES Performance Tuning (cont.) ● Client considerations ○ Idempotent request ■ Requests that may change server state should be idempotent ○ Connection pooling ■ Avoid creating a request for every query ○ Bulk update request ■ Can request bulk update when needed ■ Catch: No rollback if operation fails during update
  • 47. ● Highly customizable dashboarding ● Kibana 3 ○ Just a front-end (Angular.js + jQuery + Elastic.js) ● Kibana 4 ○ Standalone web application ○ Node.js ○ Float (jQuery plotting library) ● Developed and maintained by ElasticSearch as a part of ELK Stack ● Github: https://github.com/elastic/kibana Kibana
  • 48. Why Kibana? ● Built to work with Elasticsearch ● Gives shapes to data ● Very flexible interface ● Easy to export data ● Easy setup procedure
  • 49. Kibana Setup ● Configuration ○ Config file <KIBANA_HOME>/config/kibana.yml ● To start Kibana <KIBANA_HOME>/bin/kibana ● Access http://localhost:5601
  • 50. ● Settings ○ Tell Kibana from where to pull data ○ Configure an index pattern ● Discover ○ Displays all available documents from the search result based on a specific timespan ○ Visualizes available data using histogram ○ Search using Lucene Query Syntax Kibana Navigation
  • 51. Kibana Navigation (cont.) ● Visualize ○ Creates visualizations like area chart, pie chart, data table, tile map etc using appropriate data ● Dashboard ○ Several visualizations can be placed in a dashboard ○ Dashboard can have data from multiple indices ○ Saves you from creating frequently needed visualizations over and over again
  • 52. Kibana Access Control ● No authentication or role based dashboard access support out of the box ● Basic authentication can be done from a proxy server (e.g. nginx) ● Use Shield by ElasticSearch ○ Authentication services for both ES and Kibana ○ Role based access control for both ES and Kibana ○ Easy to integrate with OAuth, LDAP ○ Audit logging with complete record of user and system activities ○ Easy SSL/TLS configuration
  • 53. To Wrap It Up...
  • 54. How About A Demo? ● Two months worth of HTTP access logs of NASA Kennedy Space Center of Florida (openly accessible from here) ● More than 3 million requests from various sources ● Around 400 MB server log dump
  • 55. To Explore More... ● Fluentd Documentation http://docs.fluentd.org/articles/quickstart ● Elasticsearch Reference https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html ● Elasticsearch from the bottom up series https://www.elastic.co/blog/found-elasticsearch-from-the-bottom-up ● Kibana User Guide https://www.elastic.co/guide/en/kibana/current/index.html