SlideShare a Scribd company logo
Logging infrastructure in PaaS
         with Fluentd



        Yohei Sasaki / Waldemar Quevedo
              Paas Dev&Ops team
                                          1	

             Rakuten. Inc, 22/08/2012
About us

§  ささきと申します。日本人です。                       §  ワリと申します。メキシコ人です。
    (Sasaki, from Japan)                      (Wally, from Mexico)

§  Living in Japan since 1982.           §  Living in Tokyo since 2010.

§  Tech Lead of the PaaS Dev&Ops         §  Member of the PaaS Dev&Ops team
    team at Rakuten, Architect of             at Rakuten, programming in Ruby.
    Rakuten PaaS.
                                          §  Emacs user (org-mode rocks, try .org
§  Node.js user / node-fluentd-logger        markup in Github)

§  CouchDB, …etc                         §  OpenStreetMap (Mapnik rocks)




                                                                                2
Agenda


§  Cloud Foundry

§  Cloud Foundry + Fluentd

§  Fluentd Pros & Cons

§  Misc




                                   3
Cloud Foundry




•    Open Application Platform as a Service project

•    By VMware

•    Written in Ruby

•    OpenSource
     http://github.com/cloudfoundry/vcap

•    Hosted version
     http://www.cloudfoundry.com/




                                                      4
Why Cloud Foundry?


•    Last year it was decided to introduce Cloud Foundry to build a PaaS
     in Rakuten
     http://techtarget.itmedia.co.jp/tt/news/1111/28/news02.html
     http://www.slideshare.net/rakutentech/cloud-foundry-10423477

•    Main points:
      –    Open Source
      –    Separation of concerns from IaaS
      –    Scalable architecture
      –    Multi language




                                                                           5
What Cloud Foundry does?


•    Easy to deploy applications!!

      $ mkdir app.js
      $ vi app.js
      $ vmc push yssk22-myapp
      $ vmc instances yssk22-myapp 3



•    Not easy to deploy business ready applications yet.
      –  We are now solving our own issues by modifying Cloud Foundry source

      –  One critical thing is Logging!

      –  Now we’ve solved this matter basically, let’s share our case study.




                                                                               6
Current logging issue in Cloud Foundry


$ vmc push yssk22-myapp!
!
$ curl http://yssk22-myapp.cloudfoundry.com/!
!
$ vmc logs yssk22-myapp!
!
[Wed, 22 Aug 2012 08:03:48 GMT] Hello World! !
!
$ vmc update yssk22-myapp!
!
$ vmc logs yssk22-myapp!




                                                 7
Current logging issue in Cloud Foundry


$ vmc push yssk22-myapp!
!
$ curl http://yssk22-myapp.cloudfoundry.com/!
!
$ vmc logs yssk22-myapp!
!
[Wed, 22 Aug 2012 08:03:48 GMT] Hello World! !
!
$ vmc update yssk22-myapp!
!
$ vmc logs yssk22-myapp!




                  Oops, logs are gone.
                                                 8
Persisting logs is a must for business applications!


  •    Monitoring
  •    Analysis
  •    Visualization

  Ask a data scientist =>




Sorry we lost
everything :P


  http://www.slideshare.net/doryokujin/hadoop-and-the-data-scientist
                                                                       9
Cloud Foundry does not persists the logs from apps…


  •    Enter Fluentd!




                                                      10
Brief overview of Cloud Foundry architecture




                                                        Droplet
                                                        Execution
                                                        Agent




Source: http://www.slideshare.net/derekcollison/design-of-cloud-foundry
                                                                          11
Approach

Attach a Fluentd collector to one application instance upon dispatch.

         DEA

           app        fluentd


           app        fluentd


                                              Log Storage




         DEA

           app        fluentd


           app        fluentd




                                                                        12
Collecting the logs from the apps


DEA
                        •    Log collector monitors changes in the files
 app   fluentd                –  Stdout, stderr logs in general
                              –  Catalina, manager, host-manager logs for Java
                              –  error.log for PHP apps
 app   fluentd


 app   fluentd          •    Also makes available:
                              –  VCAP_LOG_PORT env variable to flush logs
                                 directly
 app   fluentd

                              –  VCAP_LOG_STREAM_PORT to inspect the
                                 logs in realtime
 app   fluentd




                                                                                 13
Collecting the logs from the apps


DEA

 app          fluentd                   Log Storage




Fluent::Logger => VCAP_LOG_PORT
Sends logs directly to Fluentd making
unnecessary having to write to file.    VCAP_LOG_STREAM_PORT
                                        Streams the logs to a client
                                        {‘type’: ‘serverLog’, ‘text’: ‘Hello World’, ‘level’: ‘INFO’}




                                                                                                        14
Small setup for collecting the logs




DEA                                                     CloudController

 app   fluentd

                         Log Storage Server
 app   fluentd                                                /logs/:path
                           fluentd           Rack app

                              Collected log files
DEA
                         Log Storage Server             CloudController
 app   fluentd

                                             Rack app
 app   fluentd
                              Collected log files             /logs/:path




                                                                            15
How is it setup?
app/ !
fluentd/!                         Attached to an application instance on
 |-- stderr.stat (1)!
                                  startup by DEA
 |-- stdout.stat (2)!
                                  •    (1) and (2) is a “stat file” used by the input plugin,
 |-- fluentd.conf   (3)!
                                       which allows it to pick up from the last position it
 |-- startup        (4)!               had monitored.
 |-- stop           (5)!
fluentd_child.pid   (6)!
                                  •    (3) is the configuration of the plugins dynamically
                                       generated by the DEA
fluentd.pid         (7)!
logs/!                            •    (4) and (5) are the scripts executed to manage the
 |-- fluentd.log    (8)!               fluentd process

 |-- stdout.log!
                                  •    (6) and (7) are the supervisor and main process
 |-- stderr.log!                       ids from Fluentd
ruby!
run.pid!                          •    (8) is where any logs produced by the logging
                                       daemon are stored
startup!
stop!


                                                                                                16
fluentd.conf :: Input configuration
!
                                        Set up VCAP_LOG_PORT to flush the logs
<source>!
                                        directly
    type forward!
    port 12345!
</source>!
!
<source>!
     type cf_app_logs!
     instance_dir   /var/vcap.local/dea/apps/appname-0-3e9676485562c64d81a61de2df05903a!
     runtime        ruby19!
     framework      sinatra!
     tag            logs.storage!
</source>!
!
!
                                         Specify runtime and dir to monitor files




                                                                                      17
fluentd.conf :: Output configuration
<match logs.**>!
    type copy!                                       Settings for when forwarding
    <store>!                                         to the log storage, we include user
      type cf_app_forward!                           information here so that it cannot be
      flush_interval       5s!                       overrided by a logging library.
      buffer_type file!
      buffer_path fluentd/fluentd_buffer!
!
      cf_app_user                foo@example.com!
      cf_app_name                appname!
      cf_app_instance_id         3e9676485562c64d81a61de2df05903a!
      cf_app_instance_index 0!




                                                                                             18
fluentd.conf :: Output configuration
    <server>!
      name logserver!               Location of the log storage server:
      host 192.168.2.1!             -  We use a active-standby setup at the
      port 4224!                       moment.
    </server>!
                                    -  When primary Logserver is down, logs
    <server>!
                                       are forwarded to the one on standby.
      name backup_logserver!
      host 192.168.2.2!
      port 4224!
                                    When both are down, fluentd buffers to
      standby!
                                    files the logs locally until one of them is
    </server>!                      available.
  </store>!
  <store>!
     type cf_app_logs_streaming!
     port 43208!
  </store>!
</match>!


                   Set up VCAP_LOG_STREAM port to
                   enable tail –f like support.
                                                                                  19
…And now that we managed to collect the logs,

we also can support the following 2 commands:




                                                20
vmc tail




           21
vmc log-storage




                  22
What we could do


•    Persisting the logs in Cloud Foundry is a must!

•    Support to persist the logs is a key issue in adoption of Cloud
     Foundry for developing application services.

•    Thanks to Fluentd we could enable users to have log archives in a
     straightforward way.

•    Cloud Foundry and Fluentd themselves are both written in Ruby so
     integration was relatively easy.




                                                                         23
What we could not do

•  It was difficult to let the user have access to the logs from Nginx
   (used as a Router in CF)
 # Sample release process!
 vmc push app-v1 --runtime ruby19            => app-v1.cf.rakuten.co.jp!
 vmc map     app-v1 olympics.rakuten.co.jp   => Released!!
 vmc push app-v2 --runtime ruby19            => app-v2.cf.rakuten.co.jp!
 vmc map     app-v2 olympics.rakuten.co.jp   => Load balancing between apps!
 vmc unmap     app-v1 olympics.rakuten.co.jp => Release 2 complete.!


•  Then the app-v1.cf.rakuten.co.jp subdomain becomes available
   to other user.
•  Need to keep track that user X had Y domain at Z time for
   application named A in real time while storing the logs.



                                                                               24
Fluentd: Pros and Cons


•    Pros
     –  Easy to include in Cloud Foundry compared to other solutions
            •    Possible to include it like gem 'fluentd' in a Ruby component
     –  Easy to change storage technology depending on scale
     –  Easy to extend
     –  Growing community o/


•    Cons
     –  Fluentd needs better testing tools
     –  Better materials about Fluentd from the community?
            •  Learning curve is already low
            •  Just we need to share more about how we are using Fluentd
            •  e.g. 'The Little Fluentd Book', 'Advanced Fluentd Recipes’
     –  Cool.io is not maintained




                                                                                 25
Misc: Playing with the message bus


•    Cloud Foundry is built with Eventmachine.

•    Fluentd is built with Cool.io.

•    Cool.io and Eventmachine do not play along very well.

•    The message bus from Cloud Foundry named NATS is also built
     using Eventmachine.




                                                                   26
Misc: NATS input plugin

# This works, though a warning is displayed from Cool.io overriding Eventmachine!
require 'nats/client'!
!
module Fluent!
    class NatsInput < Input!
      Plugin.register_input('nats', self)!
      def run!
        NATS.start(:uri => @nats_connection_uri) do!
!
             # Triggered when an url changing event occurs (remap, change)!
             NATS.subscribe('dea.update') do |msg|!
               Engine.emit('logs.dea_update', Time.now.to_i, msg)!
             end!
!
             # Triggered when an application is started or dea is started!
             NATS.subscribe('dea.*.start') do |msg|!
               Engine.emit('logs.dea_start', Time.now.to_i, msg)!
             end!
        end!
      end!
                                                                                    27
Misc: Adding new forwarding nodes
                                       dynamically through NATS?
# DEA
@droplets.each_value do |instance|
   begin
    instance_collector = Fluent::Logger::FluentLogger.new('logs', instance[:logging_ip], instance[:logging_port])
    instance_collector.post('storage', {'type': 'serverConf', 'host': '127.0.0.1', 'port': 23938 })
   rescue => e
    @logger.error "Error: #{e} -- #{e.backtrace}"
   end
  end

# Extended Forward plugin
module Fluent
  class CloudfoundryAppForwardOutput < ForwardOutput
   Plugin.register_output('cf_app_forward', self)
   def emit(tag, es, chain)
     es.each do |emit_time, record|
     # Add a new forwarding server
     if record.has_key?('type') and record['type'] == 'serverConf’
         add_node(record['host'], record['port’])
        next
     end
                                                                                                                    28
FIN


You can enable log collection to your Cloud Foundry by merging this
patch:




https://github.com/rakutentech/dea/commit/
64d271904de1e195cc90ca1958eadf704f530d94

Checkout our github repo for more Cloud Foundry related things:
https://github.com/rakutentech/

That’s all, thanks!

ご清聴ありがとうございました!


                                                                      29

More Related Content

PDF
GBDC 勉強会 #6 Java イベントレポート 2016
PDF
Deployment With Subversion - Lorna Mitchell
 
PPTX
Introduction to Docker
PDF
Software And The Taste Of Mayo - Marco Tabini
 
PDF
SlapOS Presentation at VW2011 Seoul
PDF
Concourse Workshop
PPTX
Custom Buildpacks and Data Services
GBDC 勉強会 #6 Java イベントレポート 2016
Deployment With Subversion - Lorna Mitchell
 
Introduction to Docker
Software And The Taste Of Mayo - Marco Tabini
 
SlapOS Presentation at VW2011 Seoul
Concourse Workshop
Custom Buildpacks and Data Services

What's hot (20)

PDF
DCEU 18: Tips and Tricks of the Docker Captains
PDF
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
PDF
Techtalks: taking docker to production
ODP
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
PDF
Open Dayligth usando SDN-NFV
PDF
jbang: Unleash the power of Java for shell scripting
PDF
ADB(Android Debug Bridge): How it works?
PDF
Haj 4344-java se 9 and the application server-1
PDF
LabDocumentation
PDF
mg-ccr-ws-10122008
PDF
Building kubectl plugins with Quarkus | DevNation Tech Talk
PDF
Augmenting Flow Operations and Feedback on the Model Driven MD_SAL Approach i...
PDF
What is Rack Hijacking API
PDF
Intro to Kernel Debugging - Just make the crashing stop!
PPTX
What is CocoaPods and how to setup?
PDF
Docker In Bank Unrated
PDF
Using Docker Containers to Improve Reproducibility in Software and Web Engine...
PDF
Deploying And Monitoring Rails
PDF
Inside Android's Dalvik VM - NEJUG Nov 2011
PDF
Rishidot research briefing notes Cloudscaling
DCEU 18: Tips and Tricks of the Docker Captains
JDD2014: Docker.io - versioned linux containers for JVM devops - Dominik Dorn
Techtalks: taking docker to production
An OpenShift Primer for Developers to get your Code into the Cloud (PTJUG)
Open Dayligth usando SDN-NFV
jbang: Unleash the power of Java for shell scripting
ADB(Android Debug Bridge): How it works?
Haj 4344-java se 9 and the application server-1
LabDocumentation
mg-ccr-ws-10122008
Building kubectl plugins with Quarkus | DevNation Tech Talk
Augmenting Flow Operations and Feedback on the Model Driven MD_SAL Approach i...
What is Rack Hijacking API
Intro to Kernel Debugging - Just make the crashing stop!
What is CocoaPods and how to setup?
Docker In Bank Unrated
Using Docker Containers to Improve Reproducibility in Software and Web Engine...
Deploying And Monitoring Rails
Inside Android's Dalvik VM - NEJUG Nov 2011
Rishidot research briefing notes Cloudscaling
Ad

Viewers also liked (6)

PPTX
Cloud Foundry Overview for GITPRO 2013
PPTX
Cloud Foundry a Developer's Perspective
KEY
Cloud Foundry Bootcamp
PPTX
Cloud Foundry Diego, Lattice, Docker and more
PPTX
Cloud Native Application Framework
PDF
Introduction to Platform-as-a-Service and Cloud Foundry
Cloud Foundry Overview for GITPRO 2013
Cloud Foundry a Developer's Perspective
Cloud Foundry Bootcamp
Cloud Foundry Diego, Lattice, Docker and more
Cloud Native Application Framework
Introduction to Platform-as-a-Service and Cloud Foundry
Ad

Similar to Fluentd meetup logging infrastructure in paa s (20)

PPTX
Is 12 Factor App Right About Logging
PPTX
Core os dna_oscon
PDF
Killer Docker Workflows for Development
PPTX
Unify logz with fluentd
PDF
Spring Roo Flex Add-on
PDF
CDK Meetup: Rule the World through IaC
PDF
Containers and Orchestration approaches
PDF
Part 4: Custom Buildpacks and Data Services (Pivotal Cloud Platform Roadshow)
PDF
Server(less) Swift at SwiftCloudWorkshop 3
PPTX
Spark in the Maritime Domain
PPTX
Serverless design with Fn project
PDF
upload test 1
PPTX
Core os dna_automacon
PDF
IBM Datapower Gateways - Devops with UrbanCode Deploy
PDF
"Wie passen Serverless & Autonomous zusammen?"
PPTX
Docker - A high level introduction to dockers and containers
ODP
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
PDF
[Szjug] Docker. Does it matter for java developer?
PPTX
Accelerate your development with Docker
PDF
Accelerate your software development with Docker
Is 12 Factor App Right About Logging
Core os dna_oscon
Killer Docker Workflows for Development
Unify logz with fluentd
Spring Roo Flex Add-on
CDK Meetup: Rule the World through IaC
Containers and Orchestration approaches
Part 4: Custom Buildpacks and Data Services (Pivotal Cloud Platform Roadshow)
Server(less) Swift at SwiftCloudWorkshop 3
Spark in the Maritime Domain
Serverless design with Fn project
upload test 1
Core os dna_automacon
IBM Datapower Gateways - Devops with UrbanCode Deploy
"Wie passen Serverless & Autonomous zusammen?"
Docker - A high level introduction to dockers and containers
Extending OpenShift Origin: Build Your Own Cartridge with Bill DeCoste of Red...
[Szjug] Docker. Does it matter for java developer?
Accelerate your development with Docker
Accelerate your software development with Docker

More from Rakuten Group, Inc. (20)

PDF
EPSS (Exploit Prediction Scoring System)モニタリングツールの開発
PPTX
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
PDF
楽天における安全な秘匿情報管理への道のり
PDF
What Makes Software Green?
PDF
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
PDF
DataSkillCultureを浸透させる楽天の取り組み
PDF
大規模なリアルタイム監視の導入と展開
PDF
楽天における大規模データベースの運用
PDF
楽天サービスを支えるネットワークインフラストラクチャー
PDF
楽天の規模とクラウドプラットフォーム統括部の役割
PDF
Rakuten Services and Infrastructure Team.pdf
PDF
The Data Platform Administration Handling the 100 PB.pdf
PDF
Supporting Internal Customers as Technical Account Managers.pdf
PDF
Making Cloud Native CI_CD Services.pdf
PDF
How We Defined Our Own Cloud.pdf
PDF
Travel & Leisure Platform Department's tech info
PDF
Travel & Leisure Platform Department's tech info
PDF
OWASPTop10_Introduction
PDF
Introduction of GORA API Group technology
PDF
100PBを越えるデータプラットフォームの実情
EPSS (Exploit Prediction Scoring System)モニタリングツールの開発
コードレビュー改善のためにJenkinsとIntelliJ IDEAのプラグインを自作してみた話
楽天における安全な秘匿情報管理への道のり
What Makes Software Green?
Simple and Effective Knowledge-Driven Query Expansion for QA-Based Product At...
DataSkillCultureを浸透させる楽天の取り組み
大規模なリアルタイム監視の導入と展開
楽天における大規模データベースの運用
楽天サービスを支えるネットワークインフラストラクチャー
楽天の規模とクラウドプラットフォーム統括部の役割
Rakuten Services and Infrastructure Team.pdf
The Data Platform Administration Handling the 100 PB.pdf
Supporting Internal Customers as Technical Account Managers.pdf
Making Cloud Native CI_CD Services.pdf
How We Defined Our Own Cloud.pdf
Travel & Leisure Platform Department's tech info
Travel & Leisure Platform Department's tech info
OWASPTop10_Introduction
Introduction of GORA API Group technology
100PBを越えるデータプラットフォームの実情

Recently uploaded (20)

PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
A Presentation on Artificial Intelligence
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Encapsulation theory and applications.pdf
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
Digital-Transformation-Roadmap-for-Companies.pptx
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Chapter 3 Spatial Domain Image Processing.pdf
A Presentation on Artificial Intelligence
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Encapsulation theory and applications.pdf
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Monthly Chronicles - July 2025
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Encapsulation_ Review paper, used for researhc scholars
Reach Out and Touch Someone: Haptics and Empathic Computing

Fluentd meetup logging infrastructure in paa s

  • 1. Logging infrastructure in PaaS with Fluentd Yohei Sasaki / Waldemar Quevedo Paas Dev&Ops team 1 Rakuten. Inc, 22/08/2012
  • 2. About us §  ささきと申します。日本人です。 §  ワリと申します。メキシコ人です。 (Sasaki, from Japan) (Wally, from Mexico) §  Living in Japan since 1982. §  Living in Tokyo since 2010. §  Tech Lead of the PaaS Dev&Ops §  Member of the PaaS Dev&Ops team team at Rakuten, Architect of at Rakuten, programming in Ruby. Rakuten PaaS. §  Emacs user (org-mode rocks, try .org §  Node.js user / node-fluentd-logger markup in Github) §  CouchDB, …etc §  OpenStreetMap (Mapnik rocks) 2
  • 3. Agenda §  Cloud Foundry §  Cloud Foundry + Fluentd §  Fluentd Pros & Cons §  Misc 3
  • 4. Cloud Foundry •  Open Application Platform as a Service project •  By VMware •  Written in Ruby •  OpenSource http://github.com/cloudfoundry/vcap •  Hosted version http://www.cloudfoundry.com/ 4
  • 5. Why Cloud Foundry? •  Last year it was decided to introduce Cloud Foundry to build a PaaS in Rakuten http://techtarget.itmedia.co.jp/tt/news/1111/28/news02.html http://www.slideshare.net/rakutentech/cloud-foundry-10423477 •  Main points: –  Open Source –  Separation of concerns from IaaS –  Scalable architecture –  Multi language 5
  • 6. What Cloud Foundry does? •  Easy to deploy applications!! $ mkdir app.js $ vi app.js $ vmc push yssk22-myapp $ vmc instances yssk22-myapp 3 •  Not easy to deploy business ready applications yet. –  We are now solving our own issues by modifying Cloud Foundry source –  One critical thing is Logging! –  Now we’ve solved this matter basically, let’s share our case study. 6
  • 7. Current logging issue in Cloud Foundry $ vmc push yssk22-myapp! ! $ curl http://yssk22-myapp.cloudfoundry.com/! ! $ vmc logs yssk22-myapp! ! [Wed, 22 Aug 2012 08:03:48 GMT] Hello World! ! ! $ vmc update yssk22-myapp! ! $ vmc logs yssk22-myapp! 7
  • 8. Current logging issue in Cloud Foundry $ vmc push yssk22-myapp! ! $ curl http://yssk22-myapp.cloudfoundry.com/! ! $ vmc logs yssk22-myapp! ! [Wed, 22 Aug 2012 08:03:48 GMT] Hello World! ! ! $ vmc update yssk22-myapp! ! $ vmc logs yssk22-myapp! Oops, logs are gone. 8
  • 9. Persisting logs is a must for business applications! •  Monitoring •  Analysis •  Visualization Ask a data scientist => Sorry we lost everything :P http://www.slideshare.net/doryokujin/hadoop-and-the-data-scientist 9
  • 10. Cloud Foundry does not persists the logs from apps… •  Enter Fluentd! 10
  • 11. Brief overview of Cloud Foundry architecture Droplet Execution Agent Source: http://www.slideshare.net/derekcollison/design-of-cloud-foundry 11
  • 12. Approach Attach a Fluentd collector to one application instance upon dispatch. DEA app fluentd app fluentd Log Storage DEA app fluentd app fluentd 12
  • 13. Collecting the logs from the apps DEA •  Log collector monitors changes in the files app fluentd –  Stdout, stderr logs in general –  Catalina, manager, host-manager logs for Java –  error.log for PHP apps app fluentd app fluentd •  Also makes available: –  VCAP_LOG_PORT env variable to flush logs directly app fluentd –  VCAP_LOG_STREAM_PORT to inspect the logs in realtime app fluentd 13
  • 14. Collecting the logs from the apps DEA app fluentd Log Storage Fluent::Logger => VCAP_LOG_PORT Sends logs directly to Fluentd making unnecessary having to write to file. VCAP_LOG_STREAM_PORT Streams the logs to a client {‘type’: ‘serverLog’, ‘text’: ‘Hello World’, ‘level’: ‘INFO’} 14
  • 15. Small setup for collecting the logs DEA CloudController app fluentd Log Storage Server app fluentd /logs/:path fluentd Rack app Collected log files DEA Log Storage Server CloudController app fluentd Rack app app fluentd Collected log files /logs/:path 15
  • 16. How is it setup? app/ ! fluentd/! Attached to an application instance on |-- stderr.stat (1)! startup by DEA |-- stdout.stat (2)! •  (1) and (2) is a “stat file” used by the input plugin, |-- fluentd.conf (3)! which allows it to pick up from the last position it |-- startup (4)! had monitored. |-- stop (5)! fluentd_child.pid (6)! •  (3) is the configuration of the plugins dynamically generated by the DEA fluentd.pid (7)! logs/! •  (4) and (5) are the scripts executed to manage the |-- fluentd.log (8)! fluentd process |-- stdout.log! •  (6) and (7) are the supervisor and main process |-- stderr.log! ids from Fluentd ruby! run.pid! •  (8) is where any logs produced by the logging daemon are stored startup! stop! 16
  • 17. fluentd.conf :: Input configuration ! Set up VCAP_LOG_PORT to flush the logs <source>! directly type forward! port 12345! </source>! ! <source>! type cf_app_logs! instance_dir /var/vcap.local/dea/apps/appname-0-3e9676485562c64d81a61de2df05903a! runtime ruby19! framework sinatra! tag logs.storage! </source>! ! ! Specify runtime and dir to monitor files 17
  • 18. fluentd.conf :: Output configuration <match logs.**>! type copy! Settings for when forwarding <store>! to the log storage, we include user type cf_app_forward! information here so that it cannot be flush_interval 5s! overrided by a logging library. buffer_type file! buffer_path fluentd/fluentd_buffer! ! cf_app_user foo@example.com! cf_app_name appname! cf_app_instance_id 3e9676485562c64d81a61de2df05903a! cf_app_instance_index 0! 18
  • 19. fluentd.conf :: Output configuration <server>! name logserver! Location of the log storage server: host 192.168.2.1! -  We use a active-standby setup at the port 4224! moment. </server>! -  When primary Logserver is down, logs <server>! are forwarded to the one on standby. name backup_logserver! host 192.168.2.2! port 4224! When both are down, fluentd buffers to standby! files the logs locally until one of them is </server>! available. </store>! <store>! type cf_app_logs_streaming! port 43208! </store>! </match>! Set up VCAP_LOG_STREAM port to enable tail –f like support. 19
  • 20. …And now that we managed to collect the logs, we also can support the following 2 commands: 20
  • 21. vmc tail 21
  • 23. What we could do •  Persisting the logs in Cloud Foundry is a must! •  Support to persist the logs is a key issue in adoption of Cloud Foundry for developing application services. •  Thanks to Fluentd we could enable users to have log archives in a straightforward way. •  Cloud Foundry and Fluentd themselves are both written in Ruby so integration was relatively easy. 23
  • 24. What we could not do •  It was difficult to let the user have access to the logs from Nginx (used as a Router in CF) # Sample release process! vmc push app-v1 --runtime ruby19 => app-v1.cf.rakuten.co.jp! vmc map app-v1 olympics.rakuten.co.jp => Released!! vmc push app-v2 --runtime ruby19 => app-v2.cf.rakuten.co.jp! vmc map app-v2 olympics.rakuten.co.jp => Load balancing between apps! vmc unmap app-v1 olympics.rakuten.co.jp => Release 2 complete.! •  Then the app-v1.cf.rakuten.co.jp subdomain becomes available to other user. •  Need to keep track that user X had Y domain at Z time for application named A in real time while storing the logs. 24
  • 25. Fluentd: Pros and Cons •  Pros –  Easy to include in Cloud Foundry compared to other solutions •  Possible to include it like gem 'fluentd' in a Ruby component –  Easy to change storage technology depending on scale –  Easy to extend –  Growing community o/ •  Cons –  Fluentd needs better testing tools –  Better materials about Fluentd from the community? •  Learning curve is already low •  Just we need to share more about how we are using Fluentd •  e.g. 'The Little Fluentd Book', 'Advanced Fluentd Recipes’ –  Cool.io is not maintained 25
  • 26. Misc: Playing with the message bus •  Cloud Foundry is built with Eventmachine. •  Fluentd is built with Cool.io. •  Cool.io and Eventmachine do not play along very well. •  The message bus from Cloud Foundry named NATS is also built using Eventmachine. 26
  • 27. Misc: NATS input plugin # This works, though a warning is displayed from Cool.io overriding Eventmachine! require 'nats/client'! ! module Fluent! class NatsInput < Input! Plugin.register_input('nats', self)! def run! NATS.start(:uri => @nats_connection_uri) do! ! # Triggered when an url changing event occurs (remap, change)! NATS.subscribe('dea.update') do |msg|! Engine.emit('logs.dea_update', Time.now.to_i, msg)! end! ! # Triggered when an application is started or dea is started! NATS.subscribe('dea.*.start') do |msg|! Engine.emit('logs.dea_start', Time.now.to_i, msg)! end! end! end! 27
  • 28. Misc: Adding new forwarding nodes dynamically through NATS? # DEA @droplets.each_value do |instance| begin instance_collector = Fluent::Logger::FluentLogger.new('logs', instance[:logging_ip], instance[:logging_port]) instance_collector.post('storage', {'type': 'serverConf', 'host': '127.0.0.1', 'port': 23938 }) rescue => e @logger.error "Error: #{e} -- #{e.backtrace}" end end # Extended Forward plugin module Fluent class CloudfoundryAppForwardOutput < ForwardOutput Plugin.register_output('cf_app_forward', self) def emit(tag, es, chain) es.each do |emit_time, record| # Add a new forwarding server if record.has_key?('type') and record['type'] == 'serverConf’ add_node(record['host'], record['port’]) next end 28
  • 29. FIN You can enable log collection to your Cloud Foundry by merging this patch: https://github.com/rakutentech/dea/commit/ 64d271904de1e195cc90ca1958eadf704f530d94 Checkout our github repo for more Cloud Foundry related things: https://github.com/rakutentech/ That’s all, thanks! ご清聴ありがとうございました! 29