Sha256: 5d22b9f369f7360edc87b23e1c2a3fde49236849562a1e52fb5d4f2205f604d6
Contents?: true
Size: 1.41 KB
Versions: 9
Compression:
Stored size: 1.41 KB
Contents
# encoding: utf-8 require "logstash/util/loggable" require "logstash/util" require "concurrent" module LogStash module Instrument module PeriodicPoller class Base include LogStash::Util::Loggable DEFAULT_OPTIONS = { :polling_interval => 1, :polling_timeout => 60 } public def initialize(metric, options = {}) @metric = metric @options = DEFAULT_OPTIONS.merge(options) configure_task end def update(time, result, exception) return unless exception logger.error("PeriodicPoller: exception", :poller => self, :result => result, :exception => exception, :executed_at => time) end def collect raise NotImplementedError, "#{self.class.name} need to implement `#collect`" end def start logger.debug("PeriodicPoller: Starting", :polling_interval => @options[:polling_interval], :polling_timeout => @options[:polling_timeout]) if logger.debug? @task.execute end def stop logger.debug("PeriodicPoller: Stopping") @task.shutdown end protected def configure_task @task = Concurrent::TimerTask.new { collect } @task.execution_interval = @options[:polling_interval] @task.timeout_interval = @options[:polling_timeout] @task.add_observer(self) end end end end; end
Version data entries
9 entries across 9 versions & 1 rubygems