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
Constructor Details
#initialize(metric, options = {}) ⇒ Base
Returns a new instance of Base.
17 18 19 20 21 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 17 def initialize(metric, = {}) @metric = metric = DEFAULT_OPTIONS.merge() configure_task end |
Instance Attribute Details
#metric ⇒ Object (readonly)
Returns the value of attribute metric.
14 15 16 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 14 def metric @metric end |
Instance Method Details
#collect ⇒ Object
47 48 49 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 47 def collect raise NotImplementedError, "#{self.class.name} need to implement `#collect`" end |
#start ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 51 def start logger.debug("Starting", :polling_interval => [:polling_interval], :polling_timeout => [:polling_timeout]) if logger.debug? collect # Collect data right away if possible @task.execute end |
#stop ⇒ Object
60 61 62 63 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 60 def stop logger.debug("Stopping") @task.shutdown end |
#update(time, result, exception) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/logstash/instrument/periodic_poller/base.rb', line 23 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("Timeout exception", :poller => self, :result => result, :polling_timeout => [:polling_timeout], :polling_interval => [:polling_interval], :exception => exception.class, :executed_at => time) else logger.error("Exception", :poller => self, :result => result, :exception => exception.class, :polling_timeout => [:polling_timeout], :polling_interval => [:polling_interval], :executed_at => time) end end |