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/api.rb,
app/models/fluentd/agent.rb,
app/models/fluentd/setting.rb,
app/models/fluentd/api/http.rb,
app/models/fluentd/agent/remote.rb,
app/models/fluentd/agent/td_agent.rb,
app/models/fluentd/setting/common.rb,
app/models/fluentd/setting/out_s3.rb,
app/models/fluentd/setting/out_td.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/agent/local_common.rb,
app/models/fluentd/agent/configuration.rb,
app/models/fluentd/setting/out_forward.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, SettingsHelper
Classes: Agent, AgentsController, Api, 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
154
155
156
|
# File 'app/models/fluentd.rb', line 154
def self.exists?
File.exists?(json_path)
end
|
.instance ⇒ Object
148
149
150
151
152
|
# File 'app/models/fluentd.rb', line 148
def self.instance
return unless exists?
attr = JSON.parse(File.read(json_path))
Fluentd.new(attr)
end
|
.json_path ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'app/models/fluentd.rb', line 48
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
|
.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
67
68
69
70
71
72
73
74
|
# File 'app/models/fluentd.rb', line 67
def agent
klass = variant.underscore.camelize
Agent.const_get(klass).new({
:pid_file => pid_file,
:log_file => log_file,
:config_file => config_file,
})
end
|
#api ⇒ Object
82
83
84
|
# File 'app/models/fluentd.rb', line 82
def api
Api::Http.new(api_endpoint)
end
|
#api_endpoint ⇒ Object
86
87
88
|
# File 'app/models/fluentd.rb', line 86
def api_endpoint
end
|
#check_permission(column) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'app/models/fluentd.rb', line 108
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
175
176
177
|
# File 'app/models/fluentd.rb', line 175
def destroy
File.unlink(self.class.json_path)
end
|
#ensure_default_config_file ⇒ Object
137
138
139
140
141
142
143
|
# File 'app/models/fluentd.rb', line 137
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
94
95
96
97
98
99
100
|
# File 'app/models/fluentd.rb', line 94
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?
58
59
60
|
# File 'app/models/fluentd.rb', line 58
def fluentd?
variant == "fluentd_gem"
end
|
#label ⇒ Object
90
91
92
|
# File 'app/models/fluentd.rb', line 90
def label
"fluentd" end
|
#load_settings_from_agent_default ⇒ Object
76
77
78
79
80
|
# File 'app/models/fluentd.rb', line 76
def load_settings_from_agent_default
agent.class.default_options.each_pair do |key, value|
send("#{key}=", value)
end
end
|
#save ⇒ Object
164
165
166
167
168
169
170
171
172
173
|
# File 'app/models/fluentd.rb', line 164
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
63
64
65
|
# File 'app/models/fluentd.rb', line 63
def td_agent?
variant == "td-agent"
end
|
#update_attributes(params) ⇒ Object
158
159
160
161
162
|
# File 'app/models/fluentd.rb', line 158
def update_attributes(params)
params.each_pair do |k, v|
send("#{k}=", v)
end
end
|
#validate_permissions ⇒ Object
102
103
104
105
106
|
# File 'app/models/fluentd.rb', line 102
def validate_permissions
%w(pid_file log_file config_file).each do |column|
check_permission(column)
end
end
|