Class: Fluent::Plugin::MonitorAgentInput
- Defined in:
- lib/fluent/plugin/in_monitor_agent.rb
Defined Under Namespace
Classes: ConfigMonitorServlet, JSONConfigMonitorServlet, JSONMonitorServlet, LTSVConfigMonitorServlet, LTSVMonitorServlet, MonitorServlet
Constant Summary collapse
- MONITOR_INFO =
{ 'output_plugin' => ->(){ is_a?(::Fluent::Plugin::Output) }, 'buffer_queue_length' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer); @buffer.queue.size }, 'buffer_total_queued_size' => ->(){ throw(:skip) unless instance_variable_defined?(:@buffer); @buffer.stage_size }, 'retry_count' => ->(){ instance_variable_defined?(:@num_errors) ? @num_errors : nil }, }
- IGNORE_ATTRIBUTES =
i(@config_root_section @config @masked_config)
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes included from Fluent::PluginLoggerMixin
Class Method Summary collapse
-
.collect_children(pe, array = []) ⇒ Object
get nexted plugins (such as <store> of the copy plugin) from the plugin ‘pe` recursively.
Instance Method Summary collapse
- #all_plugins ⇒ 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.
- #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.
- #shutdown ⇒ Object
- #start ⇒ Object
Methods included from Fluent::PluginHelper::Mixin
Methods included from Fluent::PluginLoggerMixin
#configure, included, #initialize, #terminate
Methods included from Fluent::PluginId
#configure, #plugin_id, #plugin_id_configured?, #plugin_id_for_test?
Methods inherited from Base
#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configure, #configured?, #has_router?, #initialize, #inspect, #shutdown?, #started?, #stop, #stopped?, #terminate, #terminated?
Methods included from SystemConfig::Mixin
#system_config, #system_config_override
Methods included from Configurable
#config, #configure, included, #initialize, lookup_type, register_type
Class Method Details
.collect_children(pe, array = []) ⇒ Object
get nexted plugins (such as <store> of the copy plugin) from the plugin ‘pe` recursively
283 284 285 286 287 288 289 290 291 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 283 def self.collect_children(pe, array=[]) array << pe if pe.is_a?(Fluent::Plugin::MultiOutput) || pe.is_a?(Fluent::MultiOutput) && pe.respond_to?(:outputs) pe.outputs.each {|nop| collect_children(nop, array) } end array end |
Instance Method Details
#all_plugins ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 258 def all_plugins array = [] # get all input plugins array.concat Fluent::Engine.root_agent.inputs # get all output plugins Fluent::Engine.root_agent.outputs.each { |o| MonitorAgentInput.collect_children(o, array) } # get all filter plugins Fluent::Engine.root_agent.filters.each { |f| MonitorAgentInput.collect_children(f, array) } Fluent::Engine.root_agent.labels.each { |name, l| # TODO: Add label name to outputs / filters for identifing plugins l.outputs.each { |o| MonitorAgentInput.collect_children(o, array) } l.filters.each { |f| MonitorAgentInput.collect_children(f, array) } } array end |
#fluentd_opts ⇒ Object
388 389 390 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 388 def fluentd_opts @fluentd_opts ||= get_fluentd_opts end |
#get_fluentd_opts ⇒ Object
392 393 394 395 396 397 398 399 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 392 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
339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 339 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.has_key?(:with_config) || 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 => e log.warn "unexpected error in monitoring plugins", key: key, plugin: pe.class, error: e end } # 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 end obj end |
#plugin_category(pe) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 375 def plugin_category(pe) case pe when Fluent::Plugin::Input 'input'.freeze when Fluent::Plugin::Output, 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
308 309 310 311 312 313 314 315 316 317 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 308 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
295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 295 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
330 331 332 333 334 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 330 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
321 322 323 324 325 326 327 328 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 321 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 |
#shutdown ⇒ Object
242 243 244 245 246 247 248 249 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 242 def shutdown if @srv @srv.shutdown @srv = nil end super end |
#start ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/fluent/plugin/in_monitor_agent.rb', line 210 def start super log.debug "listening monitoring http server on http://#{@bind}:#{@port}/api/plugins" @srv = WEBrick::HTTPServer.new({ BindAddress: @bind, Port: @port, Logger: WEBrick::Log.new(STDERR, WEBrick::Log::FATAL), AccessLog: [], }) @srv.mount('/api/plugins', LTSVMonitorServlet, self) @srv.mount('/api/plugins.json', JSONMonitorServlet, self) @srv.mount('/api/config', LTSVConfigMonitorServlet, self) @srv.mount('/api/config.json', JSONConfigMonitorServlet, self) thread_create :in_monitor_agent_servlet do @srv.start end if @tag log.debug "tag parameter is specified. Emit plugins info to '#{@tag}'" opts = {with_config: false} timer_execute(:in_monitor_agent_emit, @emit_interval, repeat: true) { es = Fluent::MultiEventStream.new now = Fluent::Engine.now plugins_info_all(opts).each { |record| es.add(now, record) } router.emit_stream(@tag, es) } end end |