Class: LogStash::Agent
- Inherits:
-
Object
- Object
- LogStash::Agent
- Includes:
- Util::Loggable
- Defined in:
- lib/logstash/agent.rb
Constant Summary collapse
- STARTED_AT =
Time.now.freeze
Instance Attribute Summary collapse
-
#dispatcher ⇒ Object
readonly
Returns the value of attribute dispatcher.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#pipelines ⇒ Object
readonly
Returns the value of attribute pipelines.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
-
#webserver ⇒ Object
readonly
Returns the value of attribute webserver.
Instance Method Summary collapse
- #execute ⇒ Object
- #id ⇒ Object
- #id_path ⇒ Object
-
#initialize(settings = LogStash::SETTINGS) ⇒ Agent
constructor
initialize method for LogStash::Agent.
-
#register_pipeline(pipeline_id, settings = @settings) ⇒ Object
register_pipeline - adds a pipeline to the agent’s state.
- #reload_state! ⇒ Object
- #running_pipelines? ⇒ Boolean
- #shutdown ⇒ Object
- #stop_collecting_metrics ⇒ Object
-
#uptime ⇒ Fixnum
Calculate the Logstash uptime in milliseconds.
Methods included from Util::Loggable
Constructor Details
#initialize(settings = LogStash::SETTINGS) ⇒ Agent
initialize method for LogStash::Agent
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/logstash/agent.rb', line 33 def initialize(settings = LogStash::SETTINGS) @logger = self.class.logger @settings = settings @auto_reload = setting("config.reload.automatic") @pipelines = {} @name = setting("node.name") @http_host = setting("http.host") @http_port = setting("http.port") @http_environment = setting("http.environment") # Generate / load the persistent uuid id @config_loader = LogStash::Config::Loader.new(@logger) @reload_interval = setting("config.reload.interval") @upgrade_mutex = Mutex.new @collect_metric = setting("metric.collect") # Create the collectors and configured it with the library configure_metrics_collectors @reload_metric = metric.namespace([:stats, :pipelines]) @dispatcher = LogStash::EventDispatcher.new(self) LogStash::PLUGIN_REGISTRY.hooks.register_emitter(self.class, dispatcher) dispatcher.fire(:after_initialize) end |
Instance Attribute Details
#dispatcher ⇒ Object (readonly)
Returns the value of attribute dispatcher.
25 26 27 |
# File 'lib/logstash/agent.rb', line 25 def dispatcher @dispatcher end |
#logger ⇒ Object
Returns the value of attribute logger.
26 27 28 |
# File 'lib/logstash/agent.rb', line 26 def logger @logger end |
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
25 26 27 |
# File 'lib/logstash/agent.rb', line 25 def metric @metric end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
25 26 27 |
# File 'lib/logstash/agent.rb', line 25 def name @name end |
#pipelines ⇒ Object (readonly)
Returns the value of attribute pipelines.
25 26 27 |
# File 'lib/logstash/agent.rb', line 25 def pipelines @pipelines end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
25 26 27 |
# File 'lib/logstash/agent.rb', line 25 def settings @settings end |
#webserver ⇒ Object (readonly)
Returns the value of attribute webserver.
25 26 27 |
# File 'lib/logstash/agent.rb', line 25 def webserver @webserver end |
Instance Method Details
#execute ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/logstash/agent.rb', line 62 def execute @thread = Thread.current # this var is implicilty used by Stud.stop? @logger.debug("starting agent") start_pipelines start_webserver return 1 if clean_state? Stud.stoppable_sleep(@reload_interval) # sleep before looping if @auto_reload Stud.interval(@reload_interval) { reload_state! } else while !Stud.stop? if clean_state? || running_pipelines? sleep 0.5 else break end end end end |
#id ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/logstash/agent.rb', line 141 def id return @id if @id uuid = nil if ::File.exists?(id_path) begin uuid = ::File.open(id_path) {|f| f.each_line.first.chomp } rescue => e logger.warn("Could not open persistent UUID file!", :path => id_path, :error => e., :class => e.class.name) end end if !uuid uuid = SecureRandom.uuid logger.info("No persistent UUID file found. Generating new UUID", :uuid => uuid, :path => id_path) begin ::File.open(id_path, 'w') {|f| f.write(uuid) } rescue => e logger.warn("Could not write persistent UUID file! Will use ephemeral UUID", :uuid => uuid, :path => id_path, :error => e., :class => e.class.name) end end @id = uuid end |
#id_path ⇒ Object
175 176 177 |
# File 'lib/logstash/agent.rb', line 175 def id_path @id_path ||= ::File.join(settings.get("path.data"), "uuid") end |
#register_pipeline(pipeline_id, settings = @settings) ⇒ Object
register_pipeline - adds a pipeline to the agent’s state
90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/logstash/agent.rb', line 90 def register_pipeline(pipeline_id, settings = @settings) pipeline_settings = settings.clone pipeline_settings.set("pipeline.id", pipeline_id) pipeline = create_pipeline(pipeline_settings) return unless pipeline.is_a?(LogStash::Pipeline) if @auto_reload && pipeline.non_reloadable_plugins.any? @logger.error(I18n.t("logstash.agent.non_reloadable_config_register"), :pipeline_id => pipeline_id, :plugins => pipeline.non_reloadable_plugins.map(&:class)) return end @pipelines[pipeline_id] = pipeline end |
#reload_state! ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/logstash/agent.rb', line 105 def reload_state! @upgrade_mutex.synchronize do @pipelines.each do |pipeline_id, pipeline| next if pipeline.settings.get("config.reload.automatic") == false begin reload_pipeline!(pipeline_id) rescue => e @reload_metric.namespace([pipeline_id.to_sym, :reloads]).tap do |n| n.increment(:failures) n.gauge(:last_error, { :message => e., :backtrace => e.backtrace}) n.gauge(:last_failure_timestamp, LogStash::Timestamp.now) end @logger.error(I18n.t("oops"), :message => e., :class => e.class.name, :backtrace => e.backtrace) end end end end |
#running_pipelines? ⇒ Boolean
179 180 181 182 183 |
# File 'lib/logstash/agent.rb', line 179 def running_pipelines? @upgrade_mutex.synchronize do @pipelines.select {|pipeline_id, _| running_pipeline?(pipeline_id) }.any? end end |
#shutdown ⇒ Object
135 136 137 138 139 |
# File 'lib/logstash/agent.rb', line 135 def shutdown stop_collecting_metrics stop_webserver shutdown_pipelines end |
#stop_collecting_metrics ⇒ Object
130 131 132 133 |
# File 'lib/logstash/agent.rb', line 130 def stop_collecting_metrics @collector.stop @periodic_pollers.stop end |
#uptime ⇒ Fixnum
Calculate the Logstash uptime in milliseconds
126 127 128 |
# File 'lib/logstash/agent.rb', line 126 def uptime ((Time.now.to_f - STARTED_AT.to_f) * 1000.0).to_i end |