Module: Fluentd::Agent::LocalCommon

Included in:
FluentdGem, TdAgent
Defined in:
app/models/fluentd/agent/local_common.rb

Instance Method Summary collapse

Instance Method Details

#configObject



18
19
20
# File 'app/models/fluentd/agent/local_common.rb', line 18

def config
  File.read(config_file)
end

#config_append(content) ⇒ Object



28
29
30
31
32
33
# File 'app/models/fluentd/agent/local_common.rb', line 28

def config_append(content)
  File.open(config_file, "a") do |f|
    f.write "\n"
    f.write content
  end
end

#config_write(content) ⇒ Object



22
23
24
25
26
# File 'app/models/fluentd/agent/local_common.rb', line 22

def config_write(content)
  File.open(config_file, "w") do |f|
    f.write content
  end
end

#configurationObject



50
51
52
53
54
# File 'app/models/fluentd/agent/local_common.rb', line 50

def configuration
  if File.exists? config_file
    ::Fluentd::Agent::Configuration.new(config_file)
  end
end

#logObject



13
14
15
16
# File 'app/models/fluentd/agent/local_common.rb', line 13

def log
  return "" unless File.exists?(log_file)
  File.read(log_file) # TODO: large log file
end

#log_tail(limit = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/fluentd/agent/local_common.rb', line 35

def log_tail(limit = nil)
  return [] unless File.exists?(log_file)

  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

#running?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
9
10
11
# File 'app/models/fluentd/agent/local_common.rb', line 4

def running?
  begin
    pid && Process.kill(0, pid)
  rescue Errno::ESRCH
    File.unlink(pid_file) # no needed any more
    false
  end
end