Class: Bigcommerce::Prometheus::Collectors::Base
- Inherits:
-
Object
- Object
- Bigcommerce::Prometheus::Collectors::Base
- Defined in:
- lib/bigcommerce/prometheus/collectors/base.rb
Overview
Base class for collectors
Direct Known Subclasses
Class Method Summary collapse
-
.start(*args, &block) ⇒ Object
Start the collector.
-
.stop ⇒ Object
Stop the collector.
Instance Method Summary collapse
-
#collect(metrics = {}) ⇒ Hash
Collect metrics.
-
#initialize(client: nil, type: nil, frequency: nil, options: nil) ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
Run the collector and send stats.
Constructor Details
#initialize(client: nil, type: nil, frequency: nil, options: nil) ⇒ Base
Returns a new instance of Base.
57 58 59 60 61 62 63 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 57 def initialize(client: nil, type: nil, frequency: nil, options: nil) @client = client || Bigcommerce::Prometheus.client @type = type || self.class.to_s.downcase.gsub('::', '_').gsub('collector', '') @frequency = frequency || Bigcommerce::Prometheus.collector_collection_frequency @options = || {} @logger = Bigcommerce::Prometheus.logger end |
Class Method Details
.start(*args, &block) ⇒ Object
Start the collector
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 28 def self.start(*args, &block) process_collector = new(*args, &block) stop if @thread @thread = Thread.new do Kernel.loop do process_collector.run end end end |
.stop ⇒ Object
Stop the collector
43 44 45 46 47 48 49 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 43 def self.stop t = @thread return unless t t.kill @thread = nil end |
Instance Method Details
#collect(metrics = {}) ⇒ Hash
Collect metrics. This should be overridden in derivative collectors
82 83 84 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 82 def collect(metrics = {}) metrics end |
#run ⇒ Object
Run the collector and send stats
68 69 70 71 72 73 74 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 68 def run metrics = {} metrics = collect(metrics) push(metrics) ensure sleep @frequency end |