Merge pull request #68 from treasure-data/friendly_fluentd_ui_gem_default

Friendly fluentd ui gem default
This commit is contained in:
uu59 2014-07-30 18:19:56 +09:00
commit 3f27a3af3e
4 changed files with 33 additions and 14 deletions

View File

@ -11,7 +11,6 @@ class Fluentd
before_validation :expand_paths before_validation :expand_paths
COLUMNS = [:id, :variant, :log_file, :pid_file, :config_file] COLUMNS = [:id, :variant, :log_file, :pid_file, :config_file]
JSON_PATH = (ENV["FLUENTD_UI_DATA_DIR"].presence || Rails.root.join("db").to_s) + "/#{Rails.env}-fluentd.json"
DEFAULT_CONF = <<-CONF.strip_heredoc DEFAULT_CONF = <<-CONF.strip_heredoc
<source> <source>
# http://docs.fluentd.org/articles/in_forward # http://docs.fluentd.org/articles/in_forward
@ -46,6 +45,16 @@ class Fluentd
%w(fluentd_gem td-agent) %w(fluentd_gem td-agent)
end end
def self.json_path
if ENV["FLUENTD_UI_DATA_DIR"].present?
dir = ENV["FLUENTD_UI_DATA_DIR"]
else
dir = ENV["HOME"] + "/.fluentd-ui/core_data"
end
FileUtils.mkdir_p(dir)
dir + "/#{Rails.env}-fluentd.json"
end
def fluentd? def fluentd?
variant == "fluentd_gem" variant == "fluentd_gem"
end end
@ -138,12 +147,12 @@ class Fluentd
def self.instance def self.instance
return unless exists? return unless exists?
attr = JSON.parse(File.read(JSON_PATH)) attr = JSON.parse(File.read(json_path))
Fluentd.new(attr) Fluentd.new(attr)
end end
def self.exists? def self.exists?
File.exists?(JSON_PATH) File.exists?(json_path)
end end
def update_attributes(params) def update_attributes(params)
@ -158,12 +167,12 @@ class Fluentd
result[col] = send(col) result[col] = send(col)
result result
end.to_json end.to_json
File.open(JSON_PATH, "w") do |f| File.open(self.class.json_path, "w") do |f|
f.write json f.write json
end && ensure_default_config_file end && ensure_default_config_file
end end
def destroy def destroy
File.unlink(JSON_PATH) File.unlink(self.class.json_path)
end end
end end

View File

@ -5,12 +5,10 @@ class Fluentd
include LocalCommon include LocalCommon
def self.default_options def self.default_options
# TODO: current default options from fluentd --setup, but root permission required for them.
# It could be more user friendly values
{ {
:pid_file => "/var/run/fluent.pid", :pid_file => "#{ENV["HOME"]}/.fluentd-ui/fluent.pid",
:log_file => "/var/log/fluent.log", :log_file => "#{ENV["HOME"]}/.fluentd-ui/fluent.log",
:config_file => "/etc/fluent/fluent.conf", :config_file => "#{ENV["HOME"]}/.fluentd-ui/fluent.conf",
} }
end end

View File

@ -9,11 +9,23 @@
= @fluentd.variant = @fluentd.variant
%div.form-group %div.form-group
= f.label :pid_file = f.label :pid_file
= f.text_field :pid_file, class: "form-control" - if @fluentd.td_agent?
= f.text_field :pid_file, class: "form-control", disabled: true
= f.hidden_field :pid_file
- else
= f.text_field :pid_file, class: "form-control"
%div.form-group %div.form-group
= f.label :log_file = f.label :log_file
= f.text_field :log_file, class: "form-control" - if @fluentd.td_agent?
= f.text_field :log_file, class: "form-control", disabled: true
= f.hidden_field :log_file
- else
= f.text_field :log_file, class: "form-control"
%div.form-group %div.form-group
= f.label :config_file = f.label :config_file
= f.text_field :config_file, class: "form-control" - if @fluentd.td_agent?
= f.text_field :config_file, class: "form-control", disabled: true
= f.hidden_field :config_file
- else
= f.text_field :config_file, class: "form-control"
= f.submit btn, class: "btn btn-primary" = f.submit btn, class: "btn btn-primary"

View File

@ -56,7 +56,7 @@ describe Fluentd do
end end
let(:fluentd) { build(:fluentd) } let(:fluentd) { build(:fluentd) }
after { File.unlink(Fluentd::JSON_PATH) if File.exist?(Fluentd::JSON_PATH) } after { File.unlink(Fluentd.json_path) if File.exist?(Fluentd.json_path) }
describe "#valid?" do describe "#valid?" do
before do before do