diff --git a/Gemfile.lock b/Gemfile.lock index fe23ee1..f18f66a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -12,6 +12,8 @@ PATH i18n_generators (= 1.2.1) jbuilder (~> 2.0) jquery-rails (~> 3.1.0) + kramdown (> 1.0.0) + kramdown-haml puma rails (= 4.1.1) sass-rails (~> 4.0.3) @@ -75,7 +77,7 @@ GEM factory_girl_rails (4.4.1) factory_girl (~> 4.4.0) railties (>= 3.0.0) - fluentd (0.10.48) + fluentd (0.10.49) cool.io (>= 1.1.1, < 2.0.0, != 1.2.0) http_parser.rb (>= 0.5.1, < 0.7.0) json (>= 1.4.3) @@ -107,6 +109,9 @@ GEM railties (>= 3.0, < 5.0) thor (>= 0.14, < 2.0) json (1.8.1) + kramdown (1.3.3) + kramdown-haml (0.0.3) + haml mail (2.5.4) mime-types (~> 1.16) treetop (~> 1.4.8) @@ -215,7 +220,7 @@ GEM webrobots (0.1.1) xpath (2.0.0) nokogiri (~> 1.3) - yajl-ruby (1.2.0) + yajl-ruby (1.2.1) PLATFORMS ruby diff --git a/app/controllers/tutorials_controller.rb b/app/controllers/tutorials_controller.rb index d21b202..1f5fab5 100644 --- a/app/controllers/tutorials_controller.rb +++ b/app/controllers/tutorials_controller.rb @@ -1,5 +1,6 @@ class TutorialsController < ApplicationController before_action :find_fluentd + before_action :check_ready, only: [:chapter1, :chapter2] helper_method :tutorial_ready? def index @@ -7,7 +8,10 @@ class TutorialsController < ApplicationController end def chapter1 - return redirect_to tutorials_url unless tutorial_ready? + end + + def chapter2 + @default_conf = Fluentd::DEFAULT_CONF end def log_tail @@ -27,6 +31,10 @@ class TutorialsController < ApplicationController @fluentd = Fluentd.first end + def check_ready + return redirect_to tutorials_url unless tutorial_ready? + end + def tutorial_ready? @fluentd && @fluentd.agent.running? end diff --git a/app/models/fluentd.rb b/app/models/fluentd.rb index e33e358..6af20c7 100644 --- a/app/models/fluentd.rb +++ b/app/models/fluentd.rb @@ -8,6 +8,29 @@ class Fluentd < ActiveRecord::Base before_validation :expand_paths after_save :ensure_default_config_file + DEFAULT_CONF = <<-CONF.strip_heredoc + + type forward + port 24224 + + + type monitor_agent + port 24220 + + + type http + port 8888 + + + type debug_agent + port 24230 + + + + type stdout + + CONF + def self.variants %w(fluentd td-agent) end @@ -82,28 +105,7 @@ class Fluentd < ActiveRecord::Base return true if File.size?(config_file) File.open(config_file, "w") do |f| - f.write <<-XML.strip_heredoc - - type forward - port 24224 - - - type monitor_agent - port 24220 - - - type http - port 9880 - - - type debug_agent - port 24230 - - - - type stdout - - XML + f.write DEFAULT_CONF end end end diff --git a/app/views/tutorials/chapter1.html.erb b/app/views/tutorials/chapter1.html.erb index b120d4b..dfcd2c3 100644 --- a/app/views/tutorials/chapter1.html.erb +++ b/app/views/tutorials/chapter1.html.erb @@ -30,5 +30,5 @@

-TODO: (chapter 2: output/buffer plugin) To Be Continued→... + <%= link_to t('tutorials.chapter2.page_title') << " >>", tutorials_chapter2_path, class: "pull-right" %>

diff --git a/app/views/tutorials/chapter2.html.haml b/app/views/tutorials/chapter2.html.haml new file mode 100644 index 0000000..7ee7236 --- /dev/null +++ b/app/views/tutorials/chapter2.html.haml @@ -0,0 +1,23 @@ +- page_title t(".page_title") + +%pre + 2014-06-05 14:43:14 +0900 [info]: adding source type="http" + 2014-06-05 14:43:14 +0900 [info]: adding match pattern="debug.*" type="stdout" + +:markdown + #{t('.lesson_markdown')} + +%pre + :escaped + + type http + port 8888 + + + + type stdout + + + +%p + = link_to "<< " << t('tutorials.chapter1.page_title'), tutorials_chapter1_path, class: "pull-left" diff --git a/config/application.rb b/config/application.rb index 0a586f5..d29965a 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,6 +18,7 @@ require "haml-rails" require "jquery-rails" require "sucker_punch" require "settingslogic" +require "kramdown-haml" module FluentdUi class Application < Rails::Application diff --git a/config/locales/translation_en.yml b/config/locales/translation_en.yml index 4f64a3e..85e0ea0 100644 --- a/config/locales/translation_en.yml +++ b/config/locales/translation_en.yml @@ -116,13 +116,24 @@ en: start_tutorial: Start tutorial chapter1: <<: *tutorials_common - page_title: "Tutorial | Receive data via in_http" + page_title: "Chapter 1 | Receive data via in_http" reload_log: Reload fluend log description: You can send an arbitrary JSON data via HTTP. URL path will be tag name. learn_more: | Other input plugins are available such as in_syslog, in_tail, etc. Learn More send: Send + chapter2: + <<: *tutorials_common + page_title: "Chapter 2 | in_http and out_stdout" + lesson_markdown: | + You can see the log as above when fluentd started. + + Line 1 enable http plugin that allows to receive HTTP requests. + + Line 2 enable stdout plugin that process the data with matched `debug.*` tag. + + These settings are defined as following fluent.conf: messages: need_restart: need to restart fluentd-ui diff --git a/config/locales/translation_ja.yml b/config/locales/translation_ja.yml index 3ddacf0..e6277f9 100644 --- a/config/locales/translation_ja.yml +++ b/config/locales/translation_ja.yml @@ -116,13 +116,24 @@ ja: start_tutorial: "チュートリアルを始める" chapter1: <<: *tutorials_common - page_title: "チュートリアル | in_httpでデータを受け取る" + page_title: "Chapter 1 | in_httpでデータを受け取る" reload_log: fluentdのログを更新 description: fluentdに任意のデータをJSONで送ることができます。URLのパスがタグの名前になります。 learn_more: | 他にもin_tail, in_syslogなどのinputプラグインがあります。 Learn More send: 送信 + chapter2: + <<: *tutorials_common + page_title: "Chapter 2 | in_httpとout_stdout" + lesson_markdown: | + fluentdの起動時にこのようなログがあるかと思います。 + + この1行目でhttpが有効化されています。これでHTTPリクエストを受け付けるようになります。 + + 2行目でstdoutが有効化されています。受け取ったデータのうち、タグが`debug.*`にマッチするものはstdoutへと渡されます。 + + この2つはfluent.confでそれぞれ次のように設定されています。 messages: need_restart: fluentd-uiの再起動が必要です diff --git a/config/routes.rb b/config/routes.rb index cdb8d33..ec94b20 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -37,6 +37,7 @@ Rails.application.routes.draw do namespace :tutorials do get "/" => :index get "chapter1" + get "chapter2" get "log_tail" post "request_fluentd" end diff --git a/fluentd-ui.gemspec b/fluentd-ui.gemspec index 995053e..366f8b0 100644 --- a/fluentd-ui.gemspec +++ b/fluentd-ui.gemspec @@ -35,4 +35,6 @@ Gem::Specification.new do |spec| spec.add_dependency "settingslogic" spec.add_dependency "puma" spec.add_dependency "thor" + spec.add_dependency "kramdown", "> 1.0.0" + spec.add_dependency "kramdown-haml" end