Class: LogStash::Instrument::PeriodicPoller::Base
- Inherits:
-
Object
- Object
- LogStash::Instrument::PeriodicPoller::Base
- Includes:
- Util::Loggable
- Defined in:
- lib/logstash/instrument/periodic_poller/base.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :polling_interval => 5, :polling_timeout => 120 }
Instance Attribute Summary collapse
-
#metric ⇒ Object
readonly
Returns the value of attribute metric.
Instance Method Summary collapse
- #collect ⇒ Object
-
#initialize(metric, options = {}) ⇒ Base
constructor
A new instance of Base.
- #start ⇒ Object
- #stop ⇒ Object
- #update(time, result, exception) ⇒ Object
Methods included from Util::Loggable
included, #logger, #slow_logger
Constructor Details
#initialize(metric, options = {}) ⇒ Base
Returns a new instance of Base.
18 19 20 21 22 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 18 def initialize(metric, = {}) @metric = metric @options = DEFAULT_OPTIONS.merge() configure_task end |
Instance Attribute Details
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
15 16 17 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 15 def metric @metric end |
Instance Method Details
#collect ⇒ Object
48 49 50 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 48 def collect raise NotImplementedError, "#{self.class.name} need to implement `#collect`" end |
#start ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 52 def start logger.debug("PeriodicPoller: Starting", :polling_interval => @options[:polling_interval], :polling_timeout => @options[:polling_timeout]) if logger.debug? collect # Collect data right away if possible @task.execute end |
#stop ⇒ Object
61 62 63 64 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 61 def stop logger.debug("PeriodicPoller: Stopping") @task.shutdown end |
#update(time, result, exception) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 24 def update(time, result, exception) return unless exception if exception.is_a?(Concurrent::TimeoutError) # On a busy system this can happen, we just log it as a debug # event instead of an error, Some of the JVM calls can take a long time or block. logger.debug("PeriodicPoller: Timeout exception", :poller => self, :result => result, :polling_timeout => @options[:polling_timeout], :polling_interval => @options[:polling_interval], :exception => exception.class, :executed_at => time) else logger.error("PeriodicPoller: exception", :poller => self, :result => result, :exception => exception.class, :polling_timeout => @options[:polling_timeout], :polling_interval => @options[:polling_interval], :executed_at => time) end end |