diff --git a/app/models/fluentd/agent/common.rb b/app/models/fluentd/agent/common.rb index 781aadf..1e3105a 100644 --- a/app/models/fluentd/agent/common.rb +++ b/app/models/fluentd/agent/common.rb @@ -57,13 +57,16 @@ class Fluentd extra_options[:config_file] || self.class.default_options[:config_file] end + + # define these methods on each Agent class + %w(start stop restart).each do |method| define_method(method) do raise NotImplementedError end end - %w(running? log config config_write config_append logged_errors log_tail configuration).each do |method| + %w(running? log config config_write config_append log_tail configuration).each do |method| define_method(method) do raise NotImplementedError end diff --git a/app/models/fluentd/agent/local_common.rb b/app/models/fluentd/agent/local_common.rb index 928c3e6..38c39ac 100644 --- a/app/models/fluentd/agent/local_common.rb +++ b/app/models/fluentd/agent/local_common.rb @@ -1,11 +1,6 @@ class Fluentd class Agent module LocalCommon - def pid - return unless File.exists?(pid_file) - File.read(pid_file).to_i rescue nil - end - def running? begin pid && Process.kill(0, pid) @@ -35,6 +30,31 @@ class Fluentd f.write content end end + def log_tail(limit = nil) + limit = limit.to_i rescue 0 + limit = limit.zero? ? Settings.default_log_tail_count : limit + io = File.open(log_file) + buf = [] + reader = ::FileReverseReader.new(io) + reader.each_line do |line| + buf << line + break if buf.length >= limit + end + buf + end + + def configuration + if File.exists? config_file + ::Fluentd::Agent::Configuration.new(config_file) + end + end + + private + + def pid + return unless File.exists?(pid_file) + File.read(pid_file).to_i rescue nil + end def logged_errors(&block) return [] unless File.exist?(log_file) @@ -72,25 +92,6 @@ class Fluentd ensure io && io.close end - - def log_tail(limit = nil) - limit = limit.to_i rescue 0 - limit = limit.zero? ? Settings.default_log_tail_count : limit - io = File.open(log_file) - buf = [] - reader = ::FileReverseReader.new(io) - reader.each_line do |line| - buf << line - break if buf.length >= limit - end - buf - end - - def configuration - if File.exists? config_file - ::Fluentd::Agent::Configuration.new(config_file) - end - end end end end