Class: Fluent::Plugin::OpentelemetryMetricsInput::MonitorInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_opentelemetry_metrics.rb

Overview

Imported from Fluent::Plugin::MonitorAgentInput

Constant Summary collapse

MONITOR_INFO =

They are deprecated but remain for compatibiscripts/pluginslity

{
  "output_plugin" => -> { is_a?(::Fluent::Plugin::Output) },
  "buffer_queue_length" => lambda {
    throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer)
    @buffer.queue.size
  },
  "buffer_timekeys" => lambda {
    throw(:skip) unless instance_variable_defined?(:@buffer) && !@buffer.nil? && @buffer.is_a?(::Fluent::Plugin::Buffer)
    @buffer.timekeys
  },
  "buffer_total_queued_size" => lambda {
    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 }
}.freeze
IGNORE_ATTRIBUTES =
%i(@config_root_section @config @masked_config).freeze

Instance Method Summary collapse

Instance Method Details

#all_pluginsObject



233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/fluent/plugin/in_opentelemetry_metrics.rb', line 233

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_value do |l|
    # TODO: Add label name to outputs / filters for identifying plugins
    array.concat l.outputs
    array.concat l.filters
  end

  array
end

#get_monitor_info(pe, opts = {}) ⇒ Object

get monitor info from the plugin ‘pe` and return a hash object



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
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
# File 'lib/fluent/plugin/in_opentelemetry_metrics.rb', line 276

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 do |key, code|
    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 StandardError => 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["output"] || {})
    obj.merge!(pe.statistics["filter"] || {})
    obj.merge!(pe.statistics["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 do |sym|
        next if IGNORE_ATTRIBUTES.include?(sym)

        key = sym.to_s[1..] # removes first '@'
        iv[key] = instance_variable_get(sym)
      end
    end
    obj["instance_variables"] = iv
  elsif (ivars = opts[:ivars])
    iv = {}
    ivars.each do |name|
      iname = "@#{name}"
      iv[name] = pe.instance_variable_get(iname) if pe.instance_variable_defined?(iname)
    end
    obj["instance_variables"] = iv
  end

  obj
end

#plugin_category(pe) ⇒ Object



254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/fluent/plugin/in_opentelemetry_metrics.rb', line 254

def plugin_category(pe)
  case pe
  when Fluent::Plugin::Input
    "input"
  when Fluent::Plugin::Output, Fluent::Plugin::MultiOutput, Fluent::Plugin::BareOutput
    "output"
  when Fluent::Plugin::Filter
    "filter"
  else
    "unknown"
  end
end

#plugins_info_all(opts = {}) ⇒ Object



267
268
269
270
271
# File 'lib/fluent/plugin/in_opentelemetry_metrics.rb', line 267

def plugins_info_all(opts = {})
  all_plugins.map do |pe|
    get_monitor_info(pe, opts)
  end
end