lib/fluent/plugin/in_prometheus_monitor.rb in fluent-plugin-prometheus-0.5.0 vs lib/fluent/plugin/in_prometheus_monitor.rb in fluent-plugin-prometheus-1.0.0

- old
+ new

@@ -1,27 +1,29 @@ -require 'fluent/input' +require 'fluent/plugin/input' require 'fluent/plugin/in_monitor_agent' require 'fluent/plugin/prometheus' -module Fluent - class PrometheusMonitorInput < Input - Plugin.register_input('prometheus_monitor', self) +module Fluent::Plugin + class PrometheusMonitorInput < Fluent::Plugin::Input + Fluent::Plugin.register_input('prometheus_monitor', self) - config_param :interval, :time, :default => 5 + helpers :timer + + config_param :interval, :time, default: 5 attr_reader :registry def initialize super @registry = ::Prometheus::Client.registry end def configure(conf) super hostname = Socket.gethostname - expander = Fluent::Prometheus.placeholder_expander(log) + expander = Fluent::Plugin::Prometheus.placeholder_expander(log) placeholders = expander.prepare_placeholders({'hostname' => hostname}) - @base_labels = Fluent::Prometheus.parse_labels_elements(conf) + @base_labels = Fluent::Plugin::Prometheus.parse_labels_elements(conf) @base_labels.each do |key, value| @base_labels[key] = expander.expand(value, placeholders) end if defined?(Fluent::Plugin) && defined?(Fluent::Plugin::MonitorAgentInput) @@ -46,44 +48,12 @@ 'buffer_total_queued_size' => buffer_total_queued_size, 'retry_count' => retry_counts, } end - class TimerWatcher < Coolio::TimerWatcher - def initialize(interval, repeat, log, &callback) - @callback = callback - @log = log - super(interval, repeat) - end - - def on_timer - @callback.call - rescue - @log.error $!.to_s - @log.error_backtrace - end - end - def start super - @loop = Coolio::Loop.new - @timer = TimerWatcher.new(@interval, true, log, &method(:update_monitor_info)) - @loop.attach(@timer) - @thread = Thread.new(&method(:run)) - end - - def shutdown - super - @loop.watchers.each {|w| w.detach } - @loop.stop - @thread.join - end - - def run - @loop.run - rescue - log.error "unexpected error", :error=>$!.to_s - log.error_backtrace + timer_execute(:in_prometheus_monitor, @interval, &method(:update_monitor_info)) end def update_monitor_info @monitor_agent.plugins_info_all.each do |info| @monitor_info.each do |name, metric|