Class: Fluentd
- Inherits:
-
Object
show all
- Includes:
- ActiveModel::Model, ActiveModel::Validations::Callbacks
- Defined in:
- app/models/fluentd/agent/common.rb,
app/models/fluentd.rb,
app/models/fluentd/agent.rb,
app/models/fluentd/setting.rb,
app/models/fluentd/agent/td_agent.rb,
app/models/fluentd/setting/common.rb,
app/models/fluentd/setting/config.rb,
app/models/fluentd/setting/out_s3.rb,
app/models/fluentd/setting/out_td.rb,
app/models/fluentd/setting/in_http.rb,
app/models/fluentd/setting/in_tail.rb,
app/models/fluentd/agent/fluentd_gem.rb,
app/models/fluentd/setting/in_syslog.rb,
app/models/fluentd/setting/out_mongo.rb,
app/models/fluentd/setting/in_forward.rb,
app/models/fluentd/setting/out_stdout.rb,
app/models/fluentd/agent/configuration.rb,
app/models/fluentd/agent/td_agent/unix.rb,
app/models/fluentd/setting/out_forward.rb,
app/models/fluentd/setting_archive/note.rb,
app/models/fluentd/agent/td_agent/macosx.rb,
app/models/fluentd/agent/process_operation.rb,
app/models/fluentd/setting/in_monitor_agent.rb,
app/models/fluentd/setting/out_elasticsearch.rb,
app/models/fluentd/setting_archive/backup_file.rb,
app/models/concerns/fluentd/setting_archive/archivable.rb
Overview
pidfile
td-agent: /var/run/td-agent/td-agent.pid
- https://github.com/treasure-data/td-agent/blob/master/td-agent.logrotate#L10
- https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L25
fluentd: nothing (or --daemon PIDFILE)
logfile
td-agent: /var/log/td-agent/td-agent.log
- https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.init#L28
fluentd: stdout (or --log LOGFILE)
config file
td-agent: /etc/td-agent/td-agent.conf
- https://github.com/treasure-data/td-agent/blob/master/debian/td-agent.postinst#L69
fluentd: /etc/fluent/fluent.conf (by fluentd -s)
Defined Under Namespace
Modules: Setting, SettingArchive, SettingsHelper
Classes: Agent, AgentsController, SettingsController
Constant Summary
collapse
- COLUMNS =
[:id, :variant, :log_file, :pid_file, :config_file]
- DEFAULT_CONF =
<<-CONF.strip_heredoc
<source>
# http://docs.fluentd.org/articles/in_forward
type forward
port 24224
</source>
<source>
# http://docs.fluentd.org/articles/in_http
type http
port 9880
</source>
<source>
type monitor_agent
port 24220
</source>
<source>
type debug_agent
port 24230
</source>
<match debug.*>
# http://docs.fluentd.org/articles/out_stdout
type stdout
</match>
CONF
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.exists? ⇒ Boolean
140
141
142
|
# File 'app/models/fluentd.rb', line 140
def self.exists?
File.exists?(json_path)
end
|
.instance ⇒ Object
134
135
136
137
138
|
# File 'app/models/fluentd.rb', line 134
def self.instance
return unless exists?
attr = JSON.parse(File.read(json_path))
Fluentd.new(attr)
end
|
.json_path ⇒ Object
48
49
50
|
# File 'app/models/fluentd.rb', line 48
def self.json_path
FluentdUI.data_dir + "/#{Rails.env}-fluentd.json"
end
|
.variants ⇒ Object
44
45
46
|
# File 'app/models/fluentd.rb', line 44
def self.variants
%w(fluentd_gem td-agent)
end
|
Instance Method Details
#agent ⇒ Object
61
62
63
64
65
66
67
68
|
# File 'app/models/fluentd.rb', line 61
def agent
klass = variant.underscore.camelize
Agent.const_get(klass).new({
:pid_file => pid_file,
:log_file => log_file,
:config_file => config_file,
})
end
|
#check_permission(column) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
# File 'app/models/fluentd.rb', line 94
def check_permission(column)
path = send(column)
return if path.blank?
begin
FileUtils.mkdir_p(File.dirname(path))
rescue Errno::EACCES
errors.add(column, :lack_write_permission)
return
end
if File.exist?(path)
if File.directory?(path)
errors.add(column, :is_a_directory)
end
unless File.writable?(path)
errors.add(column, :lack_write_permission)
end
unless File.readable?(path)
errors.add(column, :lack_read_permission)
end
else
unless File.writable?(File.dirname(path))
errors.add(column, :lack_write_permission)
end
end
end
|
#destroy ⇒ Object
161
162
163
|
# File 'app/models/fluentd.rb', line 161
def destroy
File.unlink(self.class.json_path)
end
|
#ensure_default_config_file ⇒ Object
123
124
125
126
127
128
129
|
# File 'app/models/fluentd.rb', line 123
def ensure_default_config_file
return true if File.size?(config_file)
File.open(config_file, "w") do |f|
f.write DEFAULT_CONF
end
end
|
#expand_paths ⇒ Object
80
81
82
83
84
85
86
|
# File 'app/models/fluentd.rb', line 80
def expand_paths
%w(pid_file log_file config_file).each do |column|
path = send(column)
next if path.blank?
self.send("#{column}=", File.expand_path(path))
end
end
|
#fluentd? ⇒ Boolean
Also known as:
fluentd_gem?
52
53
54
|
# File 'app/models/fluentd.rb', line 52
def fluentd?
variant == "fluentd_gem"
end
|
#label ⇒ Object
76
77
78
|
# File 'app/models/fluentd.rb', line 76
def label
"fluentd" end
|
#load_settings_from_agent_default ⇒ Object
70
71
72
73
74
|
# File 'app/models/fluentd.rb', line 70
def load_settings_from_agent_default
agent.class.default_options.each_pair do |key, value|
send("#{key}=", value)
end
end
|
#save ⇒ Object
150
151
152
153
154
155
156
157
158
159
|
# File 'app/models/fluentd.rb', line 150
def save
return false unless valid?
json = COLUMNS.inject({}) do |result, col|
result[col] = send(col)
result
end.to_json
File.open(self.class.json_path, "w") do |f|
f.write json
end && ensure_default_config_file
end
|
#td_agent? ⇒ Boolean
57
58
59
|
# File 'app/models/fluentd.rb', line 57
def td_agent?
variant == "td-agent"
end
|
#update_attributes(params) ⇒ Object
144
145
146
147
148
|
# File 'app/models/fluentd.rb', line 144
def update_attributes(params)
params.each_pair do |k, v|
send("#{k}=", v)
end
end
|
#validate_permissions ⇒ Object
88
89
90
91
92
|
# File 'app/models/fluentd.rb', line 88
def validate_permissions
%w(pid_file log_file config_file).each do |column|
check_permission(column)
end
end
|