Module: Fluentd::Agent::Common
- Included in:
- FluentdGem, TdAgent
- Defined in:
- app/models/fluentd/agent/common.rb
Instance Attribute Summary collapse
-
#extra_options ⇒ Object
readonly
Returns the value of attribute extra_options.
Class Method Summary collapse
Instance Method Summary collapse
- #backup_files ⇒ Object
- #backup_files_in_new_order ⇒ Object
- #backup_files_in_old_order ⇒ Object
-
#config ⇒ Object
– config.
- #config_append(content) ⇒ Object
-
#config_backup_dir ⇒ Object
– backup methods.
- #config_file ⇒ Object
- #config_merge(content) ⇒ Object
- #config_write(content) ⇒ Object
- #configuration ⇒ Object
- #initialize(options = {}) ⇒ Object
- #log ⇒ Object
- #log_file ⇒ Object
- #pid_file ⇒ Object
- #running_config_backup_dir ⇒ Object
- #running_config_backup_file ⇒ Object
Instance Attribute Details
#extra_options ⇒ Object (readonly)
Returns the value of attribute extra_options.
26 27 28 |
# File 'app/models/fluentd/agent/common.rb', line 26 def @extra_options end |
Class Method Details
.included(base) ⇒ Object
28 29 30 |
# File 'app/models/fluentd/agent/common.rb', line 28 def self.included(base) base.include(Fluentd::Agent::ProcessOperation) end |
Instance Method Details
#backup_files ⇒ Object
111 112 113 |
# File 'app/models/fluentd/agent/common.rb', line 111 def backup_files Dir.glob(File.join("#{config_backup_dir}", "*.conf")) end |
#backup_files_in_new_order ⇒ Object
119 120 121 |
# File 'app/models/fluentd/agent/common.rb', line 119 def backup_files_in_new_order backup_files_in_old_order.reverse end |
#backup_files_in_old_order ⇒ Object
115 116 117 |
# File 'app/models/fluentd/agent/common.rb', line 115 def backup_files_in_old_order backup_files.sort end |
#config ⇒ Object
– config
60 61 62 |
# File 'app/models/fluentd/agent/common.rb', line 60 def config File.read(config_file) end |
#config_append(content) ⇒ Object
71 72 73 74 75 76 77 |
# File 'app/models/fluentd/agent/common.rb', line 71 def config_append(content) backup_config File.open(config_file, "a") do |f| f.write "\n" f.write content end end |
#config_backup_dir ⇒ Object
– backup methods
105 106 107 108 109 |
# File 'app/models/fluentd/agent/common.rb', line 105 def config_backup_dir dir = File.join(FluentdUI.data_dir, "#{Rails.env}_confg_backups") FileUtils.mkdir_p(dir) dir end |
#config_file ⇒ Object
55 56 57 |
# File 'app/models/fluentd/agent/common.rb', line 55 def config_file [:config_file] || self.class.[:config_file] end |
#config_merge(content) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/models/fluentd/agent/common.rb', line 79 def config_merge(content) if content.start_with?("<label ") label = content.slice(/<label\s+(.+?)>/, 1) key = "label:#{label}" parsed_config = parse_config(config) if parsed_config.key?(key) offset = parsed_config[key][0][:pos] + parsed_config[key][0][:size] label, sections = parse_label_section(content, offset) parsed_config[key][0][:sections]["filter"].concat(sections["filter"]) parsed_config[key][0][:sections]["match"].concat(sections["match"]) config_write(dump_parsed_config(parsed_config)) else config_append(content) end else config_append(content) end end |
#config_write(content) ⇒ Object
64 65 66 67 68 69 |
# File 'app/models/fluentd/agent/common.rb', line 64 def config_write(content) backup_config File.open(config_file, "w") do |f| f.write content end end |
#configuration ⇒ Object
98 99 100 101 102 |
# File 'app/models/fluentd/agent/common.rb', line 98 def configuration if File.exists? config_file ::Fluentd::Agent::Configuration.new(config_file) end end |
#initialize(options = {}) ⇒ Object
39 40 41 |
# File 'app/models/fluentd/agent/common.rb', line 39 def initialize( = {}) @extra_options = end |
#log ⇒ Object
51 52 53 |
# File 'app/models/fluentd/agent/common.rb', line 51 def log @log ||= FluentdLog.new(log_file) end |
#log_file ⇒ Object
47 48 49 |
# File 'app/models/fluentd/agent/common.rb', line 47 def log_file [:log_file] || self.class.[:log_file] end |
#pid_file ⇒ Object
43 44 45 |
# File 'app/models/fluentd/agent/common.rb', line 43 def pid_file [:pid_file] || self.class.[:pid_file] end |
#running_config_backup_dir ⇒ Object
123 124 125 126 127 |
# File 'app/models/fluentd/agent/common.rb', line 123 def running_config_backup_dir dir = File.join(FluentdUI.data_dir, "#{Rails.env}_running_confg_backup") FileUtils.mkdir_p(dir) dir end |
#running_config_backup_file ⇒ Object
129 130 131 |
# File 'app/models/fluentd/agent/common.rb', line 129 def running_config_backup_file File.join(running_config_backup_dir, "running.conf") end |