Class: Fluent::Plugin::MonitorAgentInput
- Defined in:
- lib/fluent/plugin/in_monitor_agent.rb
Defined Under Namespace
Classes: APIHandler, NotFoundJson
Constant Summary collapse
- MONITOR_INFO =
They are deprecated but remain for compatibility
{ 'output_plugin' => ->(){ is_a?(::Fluent::Plugin::Output) }, 'buffer_queue_length' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.queue.size }, 'buffer_timekeys' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.timekeys }, 'buffer_total_queued_size' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer); @buffer.stage_size + @buffer.queue_size }, 'retry_count' => ->(){ respond_to?(:num_errors) ? num_errors : nil }, }
- IGNORE_ATTRIBUTES =
%i(@config_root_section @config @masked_config)
- RETRY_INFO =
{ 'start' => '@start', 'steps' => '@steps', 'next_time' => '@next_time', }
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes included from Fluent::PluginLoggerMixin
Attributes inherited from Base
Instance Method Summary collapse
- #all_plugins ⇒ Object
- #configure(conf) ⇒ Object
- #fluentd_opts ⇒ Object
- #get_fluentd_opts ⇒ Object
-
#get_monitor_info(pe, opts = {}) ⇒ Object
get monitor info from the plugin ‘pe` and return a hash object.
- #get_retry_info(pe_retry) ⇒ Object
-
#initialize ⇒ MonitorAgentInput
constructor
A new instance of MonitorAgentInput.
- #multi_workers_ready? ⇒ Boolean
- #plugin_category(pe) ⇒ Object
-
#plugin_info_by_id(plugin_id, opts = {}) ⇒ Object
search a plugin by plugin_id.
-
#plugin_info_by_tag(tag, opts = {}) ⇒ Object
try to match the tag and get the info from the matched output plugin TODO: Support output in label.
- #plugins_info_all(opts = {}) ⇒ Object
-
#plugins_info_by_type(type, opts = {}) ⇒ Object
This method returns an array because multiple plugins could have the same type.
- #start ⇒ Object
Methods inherited from Input
#metric_callback, #statistics, #zero_downtime_restart_ready?
Methods included from Fluent::PluginHelper::Mixin
Methods included from Fluent::PluginLoggerMixin
Methods included from Fluent::PluginId
#plugin_id, #plugin_id_configured?, #plugin_id_for_test?, #plugin_root_dir, #stop
Methods inherited from Base
#acquire_worker_lock, #after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #called_in_test?, #close, #closed?, #configured?, #context_router, #context_router=, #fluentd_worker_id, #get_lock_path, #has_router?, #inspect, #plugin_root_dir, #reloadable_plugin?, #shutdown, #shutdown?, #started?, #stop, #stopped?, #string_safe_encoding, #terminate, #terminated?
Methods included from SystemConfig::Mixin
#system_config, #system_config_override
Methods included from Configurable
#config, #configure_proxy_generate, #configured_section_create, included, lookup_type, register_type
Constructor Details
#initialize ⇒ MonitorAgentInput
Returns a new instance of MonitorAgentInput.
179 180 181 182 183 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 179 def initialize super @first_warn = false end |
Instance Method Details
#all_plugins ⇒ Object
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 237 def all_plugins array = [] # get all input plugins array.concat Fluent::Engine.root_agent.inputs # get all output plugins array.concat Fluent::Engine.root_agent.outputs # get all filter plugins array.concat Fluent::Engine.root_agent.filters Fluent::Engine.root_agent.labels.each { |name, l| # TODO: Add label name to outputs / filters for identifying plugins array.concat l.outputs array.concat l.filters } array end |
#configure(conf) ⇒ Object
185 186 187 188 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 185 def configure(conf) super @port += fluentd_worker_id end |
#fluentd_opts ⇒ Object
392 393 394 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 392 def fluentd_opts @fluentd_opts ||= get_fluentd_opts end |
#get_fluentd_opts ⇒ Object
396 397 398 399 400 401 402 403 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 396 def get_fluentd_opts opts = {} ObjectSpace.each_object(Fluent::Supervisor) { |obj| opts.merge!(obj.) break } opts end |
#get_monitor_info(pe, opts = {}) ⇒ Object
get monitor info from the plugin ‘pe` and return a hash object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 304 def get_monitor_info(pe, opts={}) obj = {} # Common plugin information obj['plugin_id'] = pe.plugin_id obj['plugin_category'] = plugin_category(pe) obj['type'] = pe.config['@type'] obj['config'] = pe.config if opts[:with_config] # run MONITOR_INFO in plugins' instance context and store the info to obj MONITOR_INFO.each_pair {|key,code| begin catch(:skip) do obj[key] = pe.instance_exec(&code) end rescue NoMethodError => e unless @first_warn log.error "NoMethodError in monitoring plugins", key: key, plugin: pe.class, error: e log.error_backtrace @first_warn = true end rescue => e log.warn "unexpected error in monitoring plugins", key: key, plugin: pe.class, error: e end } if pe.respond_to?(:statistics) obj.merge!(pe.statistics.dig('output') || {}) obj.merge!(pe.statistics.dig('filter') || {}) obj.merge!(pe.statistics.dig('input') || {}) end obj['retry'] = get_retry_info(pe.retry) if opts[:with_retry] && pe.instance_variable_defined?(:@retry) # include all instance variables if :with_debug_info is set if opts[:with_debug_info] iv = {} pe.instance_eval do instance_variables.each {|sym| next if IGNORE_ATTRIBUTES.include?(sym) key = sym.to_s[1..-1] # removes first '@' iv[key] = instance_variable_get(sym) } end obj['instance_variables'] = iv elsif ivars = opts[:ivars] iv = {} ivars.each {|name| iname = "@#{name}" iv[name] = pe.instance_variable_get(iname) if pe.instance_variable_defined?(iname) } obj['instance_variables'] = iv end obj end |
#get_retry_info(pe_retry) ⇒ Object
367 368 369 370 371 372 373 374 375 376 377 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 367 def get_retry_info(pe_retry) retry_variables = {} if pe_retry RETRY_INFO.each_pair { |key, param| retry_variables[key] = pe_retry.instance_variable_get(param) } end retry_variables end |
#multi_workers_ready? ⇒ Boolean
190 191 192 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 190 def multi_workers_ready? true end |
#plugin_category(pe) ⇒ Object
379 380 381 382 383 384 385 386 387 388 389 390 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 379 def plugin_category(pe) case pe when Fluent::Plugin::Input 'input'.freeze when Fluent::Plugin::Output, Fluent::Plugin::MultiOutput, Fluent::Plugin::BareOutput 'output'.freeze when Fluent::Plugin::Filter 'filter'.freeze else 'unknown'.freeze end end |
#plugin_info_by_id(plugin_id, opts = {}) ⇒ Object
search a plugin by plugin_id
273 274 275 276 277 278 279 280 281 282 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 273 def plugin_info_by_id(plugin_id, opts={}) found = all_plugins.find {|pe| pe.respond_to?(:plugin_id) && pe.plugin_id.to_s == plugin_id } if found get_monitor_info(found, opts) else nil end end |
#plugin_info_by_tag(tag, opts = {}) ⇒ Object
try to match the tag and get the info from the matched output plugin TODO: Support output in label
260 261 262 263 264 265 266 267 268 269 270 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 260 def plugin_info_by_tag(tag, opts={}) matches = Fluent::Engine.root_agent.event_router.instance_variable_get(:@match_rules) matches.each { |rule| if rule.match?(tag) if rule.collector.is_a?(Fluent::Plugin::Output) || rule.collector.is_a?(Fluent::Output) return get_monitor_info(rule.collector, opts) end end } nil end |
#plugins_info_all(opts = {}) ⇒ Object
295 296 297 298 299 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 295 def plugins_info_all(opts={}) all_plugins.map {|pe| get_monitor_info(pe, opts) } end |
#plugins_info_by_type(type, opts = {}) ⇒ Object
This method returns an array because multiple plugins could have the same type
286 287 288 289 290 291 292 293 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 286 def plugins_info_by_type(type, opts={}) array = all_plugins.select {|pe| (pe.config['@type'] == type) rescue nil } array.map {|pe| get_monitor_info(pe, opts) } end |
#start ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 201 def start super log.debug { "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins for worker#{fluentd_worker_id}" } api_handler = APIHandler.new(self) http_server_create_http_server(:in_monitor_http_server_helper, addr: @bind, port: @port, logger: log, default_app: NotFoundJson) do |serv| serv.get('/api/plugins') { |req| api_handler.plugins_ltsv(req) } serv.get('/api/plugins.json') { |req| api_handler.plugins_json(req) } serv.get('/api/config') { |req| api_handler.config_ltsv(req) } serv.get('/api/config.json') { |req| api_handler.config_json(req) } end if @tag log.debug { "tag parameter is specified. Emit plugins info to '#{@tag}'" } opts = {with_config: false, with_retry: false} timer_execute(:in_monitor_agent_emit, @emit_interval, repeat: true) { es = Fluent::MultiEventStream.new now = Fluent::EventTime.now plugins_info_all(opts).each { |record| es.add(now, record) } router.emit_stream(@tag, es) } end end |