module Fluent::PluginHelper::Metrics

Attributes

_metrics[R]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 33
def initialize
  super
  @_metrics_started = false
  @_metrics = {} # usage => metrics_state
end

Public Instance Methods

after_shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 112
def after_shutdown
  metrics_operate(:after_shutdown)
  super
end
before_shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 102
def before_shutdown
  metrics_operate(:before_shutdown)
  super
end
close() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 117
def close
  metrics_operate(:close)
  super
end
configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 39
def configure(conf)
  super

  @plugin_type_or_id = if self.plugin_id_configured?
                         self.plugin_id
                       else
                         if type = (conf["@type"] || conf["type"])
                           "#{type}.#{self.plugin_id}"
                         else
                           "#{self.class.to_s.split("::").last.downcase}.#{self.plugin_id}"
                         end
                       end
end
metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:, labels: {}, prefer_gauge: false) click to toggle source
# File lib/fluent/plugin_helper/metrics.rb, line 53
def metrics_create(namespace: "fluentd", subsystem: "metrics", name:, help_text:, labels: {}, prefer_gauge: false)
  metrics = if system_config.metrics
              Fluent::Plugin.new_metrics(system_config.metrics[:@type], parent: self)
            else
              Fluent::Plugin.new_metrics(Fluent::Plugin::Metrics::DEFAULT_TYPE, parent: self)
            end
  config = if system_config.metrics
             system_config.metrics.corresponding_config_element
           else
             Fluent::Config::Element.new('metrics', '', {'@type' => Fluent::Plugin::Metrics::DEFAULT_TYPE}, [])
           end
  metrics.use_gauge_metric = prefer_gauge
  metrics.configure(config)
  # For multi workers environment, cmetrics should be distinguish with static labels.
  if Fluent::Engine.system_config.workers > 1
    labels[:worker_id] = fluentd_worker_id.to_s
  end
  labels[:plugin] = @plugin_type_or_id
  metrics.create(namespace: namespace, subsystem: subsystem, name: name, help_text: help_text, labels: labels)

  @_metrics["#{@plugin_type_or_id}_#{namespace}_#{subsystem}_#{name}"] = metrics

  metrics
end
metrics_operate(method_name, &block) click to toggle source
# File lib/fluent/plugin_helper/metrics.rb, line 78
def metrics_operate(method_name, &block)
  @_metrics.each_pair do |key, m|
    begin
      block.call(s) if block_given?
      m.__send__(method_name)
    rescue => e
      log.error "unexpected error while #{method_name}", key: key, metrics: m, error: e
    end
  end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 107
def shutdown
  metrics_operate(:shutdown)
  super
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 89
def start
  super

  metrics_operate(:start)
  @_metrics_started = true
end
stop() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 96
def stop
  super
  # timer stops automatically in super
  metrics_operate(:stop)
end
terminate() click to toggle source
Calls superclass method
# File lib/fluent/plugin_helper/metrics.rb, line 122
def terminate
  metrics_operate(:terminate)
  @_metrics = {}
  super
end