fluentd-ui 0.3.14 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of fluentd-ui might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/ChangeLog +5 -0
- data/Gemfile.lock +2 -2
- data/app/controllers/concerns/setting_concern.rb +1 -1
- data/app/controllers/concerns/setting_history_concern.rb +1 -1
- data/app/controllers/fluentd/agents_controller.rb +3 -3
- data/app/controllers/fluentd/settings_controller.rb +1 -1
- data/app/controllers/fluentd_controller.rb +2 -2
- data/app/controllers/misc_controller.rb +1 -1
- data/app/controllers/tutorials_controller.rb +1 -1
- data/app/models/fluentd/agent/common.rb +72 -37
- data/app/models/fluentd/agent/fluentd_gem.rb +4 -1
- data/app/models/fluentd/agent/process_operation.rb +61 -0
- data/app/models/fluentd/agent/td_agent.rb +0 -1
- data/app/models/fluentd/setting/out_mongo.rb +3 -2
- data/app/models/fluentd/setting/out_s3.rb +6 -7
- data/app/models/fluentd/setting/out_td.rb +1 -0
- data/app/models/fluentd_log.rb +123 -0
- data/lib/fluentd-ui/version.rb +1 -1
- data/spec/controllers/fluentd/agents_controller_spec.rb +6 -2
- data/spec/controllers/misc_controller_spec.rb +2 -2
- data/spec/models/fluentd/agent/{local_common_spec.rb → common_spec.rb} +2 -2
- data/spec/models/fluentd_log_spec.rb +171 -0
- data/spec/support/fluentd_agent_common_behavior.rb +5 -5
- metadata +52 -95
- data/app/models/fluentd/agent/local_common.rb +0 -201
@@ -1,201 +0,0 @@
|
|
1
|
-
class Fluentd
|
2
|
-
class Agent
|
3
|
-
module LocalCommon
|
4
|
-
def running?
|
5
|
-
begin
|
6
|
-
pid && Process.kill(0, pid)
|
7
|
-
rescue Errno::ESRCH
|
8
|
-
File.unlink(pid_file) # no needed any more
|
9
|
-
false
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def log
|
14
|
-
return "" unless File.exists?(log_file)
|
15
|
-
File.read(log_file) # TODO: large log file
|
16
|
-
end
|
17
|
-
|
18
|
-
def config
|
19
|
-
File.read(config_file)
|
20
|
-
end
|
21
|
-
|
22
|
-
def config_write(content)
|
23
|
-
backup_config
|
24
|
-
File.open(config_file, "w") do |f|
|
25
|
-
f.write content
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def config_append(content)
|
30
|
-
backup_config
|
31
|
-
File.open(config_file, "a") do |f|
|
32
|
-
f.write "\n"
|
33
|
-
f.write content
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def log_tail(limit = nil)
|
38
|
-
return [] unless File.exists?(log_file)
|
39
|
-
|
40
|
-
limit = limit.to_i rescue 0
|
41
|
-
limit = limit.zero? ? Settings.default_log_tail_count : limit
|
42
|
-
io = File.open(log_file)
|
43
|
-
buf = []
|
44
|
-
reader = ::FileReverseReader.new(io)
|
45
|
-
reader.each_line do |line|
|
46
|
-
buf << line
|
47
|
-
break if buf.length >= limit
|
48
|
-
end
|
49
|
-
buf
|
50
|
-
end
|
51
|
-
|
52
|
-
def configuration
|
53
|
-
if File.exists? config_file
|
54
|
-
::Fluentd::Agent::Configuration.new(config_file)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def pid
|
59
|
-
return unless File.exists?(pid_file)
|
60
|
-
return if File.zero?(pid_file)
|
61
|
-
File.read(pid_file).to_i rescue nil
|
62
|
-
end
|
63
|
-
|
64
|
-
def backup_files
|
65
|
-
Dir.glob(File.join("#{config_backup_dir}", "*.conf"))
|
66
|
-
end
|
67
|
-
|
68
|
-
def backup_files_in_old_order
|
69
|
-
backup_files.sort
|
70
|
-
end
|
71
|
-
|
72
|
-
def backup_files_in_new_order
|
73
|
-
backup_files_in_old_order.reverse
|
74
|
-
end
|
75
|
-
|
76
|
-
def dryrun(file_path = nil)
|
77
|
-
dryrun!(file_path)
|
78
|
-
true
|
79
|
-
rescue ::Fluentd::Agent::ConfigError
|
80
|
-
false
|
81
|
-
end
|
82
|
-
|
83
|
-
private
|
84
|
-
|
85
|
-
def exec_dryrun(command, file_path = nil)
|
86
|
-
Bundler.with_clean_env do
|
87
|
-
system("#{command} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL)
|
88
|
-
raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero?
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
def backup_config
|
93
|
-
return unless File.exists? config_file
|
94
|
-
|
95
|
-
FileUtils.cp config_file, File.join(config_backup_dir, "#{Time.zone.now.strftime('%Y%m%d_%H%M%S')}.conf")
|
96
|
-
|
97
|
-
remove_over_backup_files
|
98
|
-
end
|
99
|
-
|
100
|
-
def remove_over_backup_files
|
101
|
-
over_file_count = backup_files.size - ::Settings.max_backup_files_count
|
102
|
-
|
103
|
-
return if over_file_count <= 0
|
104
|
-
|
105
|
-
backup_files_in_old_order.first(over_file_count).each do |file|
|
106
|
-
note_file_attached_backup = file.sub(/#{Regexp.escape(File.extname(file))}\z/, ::Fluentd::SettingArchive::Note::FILE_EXTENSION)
|
107
|
-
FileUtils.rm(note_file_attached_backup) if File.exist? note_file_attached_backup
|
108
|
-
FileUtils.rm(file) if File.exist? file
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
def logged_errors(&block)
|
113
|
-
return [] unless File.exist?(log_file)
|
114
|
-
buf = []
|
115
|
-
io = File.open(log_file)
|
116
|
-
reader = ::FileReverseReader.new(io)
|
117
|
-
reader.each_line do |line|
|
118
|
-
unless line["error"]
|
119
|
-
if buf.present?
|
120
|
-
# NOTE: if a following log is given
|
121
|
-
# 2014-06-30 11:24:08 +0900 [error]: unexpected error error_class=Errno::EADDRINUSE error=#<Errno::EADDRINUSE: Address already in use - bind(2) for 0.0.0.0:24220>
|
122
|
-
# 2014-06-30 11:24:08 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.2/lib/ruby/2.1.0/socket.rb:206:in `bind'
|
123
|
-
# 2014-06-30 11:24:08 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.2/lib/ruby/2.1.0/socket.rb:206:in `listen'
|
124
|
-
# 2014-06-30 11:24:08 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.2/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
|
125
|
-
# the first line become a "subject", trailing lines are "notes"
|
126
|
-
# {
|
127
|
-
# subject: "2014-06-30 11:24:08 +0900 [error]: unexpected error error_class=Errno::EADDRINUSE error=#<Errno::EADDRINUSE: Address already in use - bind(2) for 0.0.0.0:24220>",
|
128
|
-
# notes: [
|
129
|
-
# 2014-06-30 11:24:08 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.2/lib/ruby/2.1.0/socket.rb:206:in `bind'
|
130
|
-
# 2014-06-30 11:24:08 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.2/lib/ruby/2.1.0/socket.rb:206:in `listen'
|
131
|
-
# 2014-06-30 11:24:08 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.2/lib/ruby/2.1.0/socket.rb:461:in `block in tcp_server_sockets'
|
132
|
-
# ]
|
133
|
-
# }
|
134
|
-
split_error_lines_to_error_units(buf.reverse).each do |error_unit|
|
135
|
-
block.call({
|
136
|
-
subject: error_unit[:subject],
|
137
|
-
notes: error_unit[:notes],
|
138
|
-
})
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
buf = []
|
143
|
-
next
|
144
|
-
end
|
145
|
-
buf << line
|
146
|
-
end
|
147
|
-
ensure
|
148
|
-
io && io.close
|
149
|
-
end
|
150
|
-
|
151
|
-
def split_error_lines_to_error_units(buf)
|
152
|
-
# NOTE: if a following log is given
|
153
|
-
#
|
154
|
-
#2014-05-27 10:54:37 +0900 [error]: unexpected error error_class=Errno::EADDRINUSE error=#<Errno::#EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 24224>
|
155
|
-
#2014-05-27 10:55:40 +0900 [error]: unexpected error error_class=Errno::EADDRINUSE error=#<Errno::#EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 24224>
|
156
|
-
# 2014-05-27 10:55:40 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cool.io-1.2.4/lib/cool.io/server.rb:57:in `initialize'
|
157
|
-
# 2014-05-27 10:55:40 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cool.io-1.2.4/lib/cool.io/server.rb:57:in `new'
|
158
|
-
#
|
159
|
-
#the first line and second line must be each "error_unit". and after third lines lines are "notes" of second error unit of .
|
160
|
-
# [
|
161
|
-
# { subject: "2014-05-27 10:54:37 +0900 [error]: unexpected error error_class=Errno::EADDRINUSE error=#<Errno::#EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 24224> ",
|
162
|
-
# notes: [] },
|
163
|
-
# { subject: "2014-05-27 10:55:40 +0900 [error]: unexpected error error_class=Errno::EADDRINUSE error=#<Errno::#EADDRINUSE: Address already in use - bind(2) for "0.0.0.0" port 24224> ",
|
164
|
-
# notes: [
|
165
|
-
# "2014-05-27 10:55:40 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cool.io-1.2.4/lib/cool.io/server.rb:57:in `initialize'",
|
166
|
-
# "2014-05-27 10:55:40 +0900 [error]: /Users/uu59/.rbenv/versions/2.1.0/lib/ruby/gems/2.1.0/gems/cool.io-1.2.4/lib/cool.io/server.rb:57:in `new'"
|
167
|
-
# ]
|
168
|
-
# },
|
169
|
-
# ]
|
170
|
-
#
|
171
|
-
return_array = []
|
172
|
-
buf.each_with_index do |b, i|
|
173
|
-
if b.match(/\A /)
|
174
|
-
return_array[-1][:notes] << b
|
175
|
-
else
|
176
|
-
return_array << { subject: b, notes: [] }
|
177
|
-
end
|
178
|
-
end
|
179
|
-
return return_array.reverse
|
180
|
-
end
|
181
|
-
|
182
|
-
def detached_command(cmd)
|
183
|
-
thread = Bundler.with_clean_env do
|
184
|
-
pid = spawn(cmd)
|
185
|
-
Process.detach(pid)
|
186
|
-
end
|
187
|
-
thread.join
|
188
|
-
thread.value.exitstatus.zero?
|
189
|
-
end
|
190
|
-
|
191
|
-
def options_to_argv(opts = {})
|
192
|
-
argv = ""
|
193
|
-
argv << " --use-v1-config"
|
194
|
-
argv << " -c #{opts[:config_file] || config_file}"
|
195
|
-
argv << " -d #{opts[:pid_file] || pid_file}"
|
196
|
-
argv << " -o #{opts[:log_file] || log_file}"
|
197
|
-
argv
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
end
|