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.
60 61 62 63 64 65 66 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 60 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
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 30 def self.start(args = {}, &block) args ||= {} 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
46 47 48 49 50 51 52 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 46 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
85 86 87 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 85 def collect(metrics = {}) metrics end |
#run ⇒ Object
Run the collector and send stats
71 72 73 74 75 76 77 |
# File 'lib/bigcommerce/prometheus/collectors/base.rb', line 71 def run metrics = {} metrics = collect(metrics) push(metrics) ensure sleep @frequency end |