in_tail guide to be fluentd/settings/in_tail

This commit is contained in:
uu59 2014-06-30 18:45:27 +09:00
parent e37197bf5c
commit bd1134f9a9
11 changed files with 229 additions and 125 deletions

View File

@ -0,0 +1,58 @@
class Fluentd::Settings::InTailController < ApplicationController
before_action :login_required
before_action :find_fluentd
def after_file_choose
@setting = Fluentd::Setting::InTail.new({
:path => params[:path],
:tag => nil,
})
end
def after_format
@setting = Fluentd::Setting::InTail.new(setting_params)
end
def confirm
@setting = Fluentd::Setting::InTail.new(setting_params)
if params[:back]
return render :after_file_choose
end
unless @setting.valid?
return render :after_format
end
end
def finish
@setting = Fluentd::Setting::InTail.new(setting_params)
if params[:back]
return render :after_format
end
unless @setting.valid?
return render "after_format"
end
if @fluentd.agent.configuration.to_s.include?(@setting.to_conf.strip)
@setting.errors.add(:base, :duplicated_conf)
return render "after_format"
end
File.open(@fluentd.agent.config_file, "a") do |f| # TODO: should update by agent class
f.write "\n"
f.write @setting.to_conf
end
@fluentd.agent.restart if @fluentd.agent.running?
redirect_to fluentd_setting_path(@fluentd)
end
private
def setting_params
setting_params = params.require(:setting).permit(:path, :format, :regexp, *Fluentd::Setting::InTail.known_formats, :tag, :rotate_wait, :pos_file, :read_from_head, :refresh_interval)
{
:pos_file => "/tmp/fluentd-#{@fluentd.id}-#{Time.now.to_i}.pos",
}.merge setting_params
end
end

View File

@ -0,0 +1,43 @@
- @setting.errors.full_messages.each do |e|
%div.alert.alert-danger= e
%div.form-group
= f.label :path
= f.hidden_field :path
= f.text_field :path, class: "form-control", disabled: true
%div.form-group
= f.label :format
= f.hidden_field :format
= f.text_field :format, class: "form-control", disabled: true
- if @setting.known_formats[@setting.format.to_sym]
- @setting.known_formats[@setting.format.to_sym].each do |key|
%label= key
= f.hidden_field key
= @setting.send(key)
%br
- else
%label= @setting.format
= f.hidden_field :regexp
= @setting.regexp
%div.form-group
= f.label :tag
= f.text_field :tag, class: "form-control"
%div.form-group
= f.label :pos_file
= f.text_field :pos_file, class: "form-control"
.well.well-sm
%h4{"data-toggle" => "collapse", "href" => "#advanced-setting"}
= icon('fa-caret-down')
= t('terms.advanced_setting')
#advanced-setting.collapse
%div.form-group
= f.label :rotate_wait
= f.text_field :rotate_wait, class: "form-control"
%div.form-group
= f.label :read_from_head
= f.check_box :read_from_head, class: "form-control"
%div.form-group
= f.label :refresh_interval
= f.text_field :refresh_interval, class: "form-control"

View File

@ -1,8 +1,8 @@
- page_title t(".page_title") - page_title t(".page_title")
= link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path = link_to t('fluentd.settings.in_tail.restart_from_first'), fluentd_setting_in_tail_path(@fluentd)
= form_for(@setting, as: "setting", url: in_tail_after_format_fluentd_setting_path(@fluentd)) do |f| = form_for(@setting, as: "setting", url: after_format_fluentd_setting_in_tail_path(@fluentd)) do |f|
- @setting.errors.full_messages.each do |e| - @setting.errors.full_messages.each do |e|
%div.alert.alert-danger= e %div.alert.alert-danger= e
@ -16,4 +16,4 @@
%p %p
= f.submit t('terms.next'), class: "btn btn-lg btn-primary pull-right" = f.submit t('terms.next'), class: "btn btn-lg btn-primary pull-right"
= link_to t('terms.prev'), in_tail_fluentd_setting_path, class: "btn btn-lg btn-default" = link_to t('terms.prev'), fluentd_setting_in_tail_path(@fluentd), class: "btn btn-lg btn-default"

View File

@ -1,8 +1,8 @@
- page_title t(".page_title") - page_title t(".page_title")
= link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path = link_to t('fluentd.settings.in_tail.restart_from_first'), fluentd_setting_in_tail_path(@fluentds)
= form_for(@setting, as: "setting", url: in_tail_confirm_fluentd_setting_path(@fluentd)) do |f| = form_for(@setting, as: "setting", url: confirm_fluentd_setting_in_tail_path(@fluentd)) do |f|
= render partial: "form", locals: { f: f } = render partial: "form", locals: { f: f }
%p %p

View File

@ -0,0 +1,13 @@
- page_title t(".page_title")
= link_to t('fluentd.settings.in_tail.restart_from_first'), fluentd_setting_in_tail_path(@fluentd)
= form_for(@setting, as: "setting", url: finish_fluentd_setting_in_tail_path(@fluentd)) do |f|
= render partial: "form", locals: { f: f }
%pre= @setting.to_conf
%p
= f.submit t('fluentd.common.finish') , class: "btn btn-lg btn-primary pull-right"
= f.submit t('terms.prev'), class: "btn btn-lg btn-default", name: "back"
.clearfix.pull-right= t('terms.notice_restart_for_config_edit')

View File

@ -1,4 +1,4 @@
- page_title t(".page_title") - page_title t(".page_title")
= render partial: "shared/vue/treeview", locals: {name: "path", action: in_tail_after_file_choose_fluentd_setting_path(@fluentd), submit_button: t('terms.next')} = render partial: "shared/vue/treeview", locals: {name: "path", action: after_file_choose_fluentd_setting_in_tail_path(@fluentd), submit_button: t('terms.next')}

View File

@ -1,13 +0,0 @@
- page_title t(".page_title")
= link_to t('fluentd.settings.restart_from_first'), in_tail_fluentd_setting_path
= form_for(@setting, as: "setting", url: in_tail_finish_fluentd_setting_path(@fluentd)) do |f|
= render partial: "form", locals: { f: f }
%pre= @setting.to_conf
%p
= f.submit t('.finish') , class: "btn btn-lg btn-primary pull-right"
= f.submit t('terms.prev'), class: "btn btn-lg btn-default", name: "back"
.clearfix.pull-right= t('.notice_restart_for_config_edit')

View File

@ -10,5 +10,6 @@
.row .row
.col-lg-4.well .col-lg-4.well
= link_to icon('fa-file-text-o fa-lg'), in_tail_fluentd_setting_path(@fluentd) = link_to(fluentd_setting_in_tail_path(@fluentd)) do
= link_to t(".setup_in_tail"), in_tail_fluentd_setting_path(@fluentd) = icon('fa-file-text-o fa-lg')
= t("fluentd.common.setup_in_tail")

View File

@ -106,62 +106,64 @@ en:
<<: *fluentd_common <<: *fluentd_common
page_title: fluentd | Log page_title: fluentd | Log
settings: settings:
restart_from_first: Restart from first
grok_manual: |
<p>
Grok syntax, for example, <code>%{INT:foo}</code> pattern given then translate to <code>/(?&lt;foo&gt;(?:[+-]?(?:[0-9]+)))/</code> regexp.
</p>
<p>
Available key/value are <a href="http://grokdebug.herokuapp.com/patterns" target="_blank">here</a>.
</p>
<h4>Example</h4>
<p>
<code>Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102</code> the log you have,<br />
<code>%{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]</code> for matching that, you will gain following result.
</p>
<table class="table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tr>
<th>month</th><td>Nov</td>
</tr>
<tr>
<th>day</th><td>29</td>
</tr>
<tr>
<th>time</th><td>17:02:55</td>
</tr>
<tr>
<th>pid</th><td>239</td>
</tr>
</table>
in_tail_option_guide: |
See <a target="_blank" href="http://docs.fluentd.org/articles/in_tail">in_tail Plugin</a> or
<a target="_blank" href="http://fluentular.herokuapp.com/">Fluentular</a> for more details.
show: show:
<<: *fluentd_common <<: *fluentd_common
edit: edit:
<<: *fluentd_common <<: *fluentd_common
in_tail_option_guide: |
See <a target="_blank" href="http://docs.fluentd.org/articles/in_tail">in_tail Plugin</a> or
<a target="_blank" href="http://fluentular.herokuapp.com/">Fluentular</a> for more details.
in_tail: in_tail:
<<: *fluentd_common <<: *fluentd_common
page_title: "File readling | Choosing File" restart_from_first: Restart from first
in_tail_after_file_choose: grok_manual: |
<<: *fluentd_common <p>
page_title: "File readling | Setting format" Grok syntax, for example, <code>%{INT:foo}</code> pattern given then translate to <code>/(?&lt;foo&gt;(?:[+-]?(?:[0-9]+)))/</code> regexp.
in_tail_after_format: </p>
<<: *fluentd_common <p>
page_title: "File readling | Other config" Available key/value are <a href="http://grokdebug.herokuapp.com/patterns" target="_blank">here</a>.
in_tail_confirm: </p>
<<: *fluentd_common
page_title: "File readling | Confirmation" <h4>Example</h4>
<p>
<code>Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102</code> the log you have,<br />
<code>%{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]</code> for matching that, you will gain following result.
</p>
<table class="table">
<thead>
<tr>
<th>Key</th>
<th>Value</th>
</tr>
</thead>
<tr>
<th>month</th><td>Nov</td>
</tr>
<tr>
<th>day</th><td>29</td>
</tr>
<tr>
<th>time</th><td>17:02:55</td>
</tr>
<tr>
<th>pid</th><td>239</td>
</tr>
</table>
show:
<<: *fluentd_common
page_title: "File readling | Choosing File"
after_file_choose:
<<: *fluentd_common
page_title: "File readling | Setting format"
after_format:
<<: *fluentd_common
page_title: "File readling | Other config"
confirm:
<<: *fluentd_common
page_title: "File readling | Confirmation"
misc: misc:
common: &misc_common common: &misc_common

View File

@ -106,61 +106,60 @@ ja:
<<: *fluentd_common <<: *fluentd_common
page_title: fluentd | ログ page_title: fluentd | ログ
settings: settings:
restart_from_first: 最初からやり直す <<: *fluentd_common
in_tail_option_guide: |
<a target="_blank" href="http://docs.fluentd.org/ja/articles/in_tail">in_tailプラグインの解説ページ</a>や
<a target="_blank" href="http://fluentular.herokuapp.com/">Fluentular</a>もご参照ください。
grok_manual: |
<p>
Grokの記法が使えます。例えば<code>%{INT:foo}</code>とすると、<code>/(?&lt;foo&gt;(?:[+-]?(?:[0-9]+)))/</code>という正規表現に変換されます。
</p>
<p>
使えるキー・値については<a href="http://grokdebug.herokuapp.com/patterns" target="_blank">リファレンス</a>をご確認ください。
</p>
<p>
<h4>例</h4>
<code>Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102</code>というログに対し、<br />
<code>%{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]</code>というパターンを適用すると以下の結果が得られます。
<table class="table">
<thead>
<tr>
<th>キー名</th>
<th>値</th>
</tr>
</thead>
<tr>
<th>month</th><td>Nov</td>
</tr>
<tr>
<th>day</th><td>29</td>
</tr>
<tr>
<th>time</th><td>17:02:55</td>
</tr>
<tr>
<th>pid</th><td>239</td>
</tr>
</table>
</p>
show: show:
<<: *fluentd_common <<: *fluentd_common
edit: edit:
<<: *fluentd_common <<: *fluentd_common
in_tail_option_guide: |
<a target="_blank" href="http://docs.fluentd.org/ja/articles/in_tail">in_tailプラグインの解説ページ</a>や
<a target="_blank" href="http://fluentular.herokuapp.com/">Fluentular</a>もご参照ください。
in_tail: in_tail:
<<: *fluentd_common <<: *fluentd_common
page_title: "ファイル読み込み | ファイルの選択" restart_from_first: 最初からやり直す
in_tail_after_file_choose: grok_manual: |
<<: *fluentd_common <p>
page_title: "ファイル読み込み | フォーマットの設定" Grokの記法が使えます。例えば<code>%{INT:foo}</code>とすると、<code>/(?&lt;foo&gt;(?:[+-]?(?:[0-9]+)))/</code>という正規表現に変換されます。
in_tail_after_format: </p>
<<: *fluentd_common <p>
page_title: "ファイル読み込み | その他の設定" 使えるキー・値については<a href="http://grokdebug.herokuapp.com/patterns" target="_blank">リファレンス</a>をご確認ください。
in_tail_confirm: </p>
<<: *fluentd_common <p>
page_title: "ファイル読み込み | 確認" <h4>例</h4>
<code>Nov 29 17:02:55 MacBook-Pro-2.local UserEventAgent[239] : cannot find fw daemon port 1102</code>というログに対し、<br />
<code>%{MONTH:month}%{SPACE}%{MONTHDAY:day} %{TIME:time} %{DATA} \[%{INT:pid}\]</code>というパターンを適用すると以下の結果が得られます。
<table class="table">
<thead>
<tr>
<th>キー名</th>
<th>値</th>
</tr>
</thead>
<tr>
<th>month</th><td>Nov</td>
</tr>
<tr>
<th>day</th><td>29</td>
</tr>
<tr>
<th>time</th><td>17:02:55</td>
</tr>
<tr>
<th>pid</th><td>239</td>
</tr>
</table>
</p>
show:
page_title: "ファイル読み込み | ファイルの選択"
after_file_choose:
page_title: "ファイル読み込み | フォーマットの設定"
after_format:
page_title: "ファイル読み込み | その他の設定"
confirm:
page_title: "ファイル読み込み | 確認"
misc: misc:
common: &misc_common common: &misc_common

View File

@ -11,11 +11,12 @@ Rails.application.routes.draw do
get "log_tail" get "log_tail"
end end
resource :setting, only: [:show, :edit, :update], module: :fluentd do resource :setting, only: [:show, :edit, :update], module: :fluentd do
get "in_tail" resource :in_tail, only: ["show"], module: :settings, controller: :in_tail do
post "in_tail_after_file_choose" post "after_file_choose"
post "in_tail_after_format" post "after_format"
post "in_tail_confirm" post "confirm"
post "in_tail_finish" post "finish"
end
end end
end end