Class: Bigcommerce::Prometheus::TypeCollectors::Base

Inherits:
PrometheusExporter::Server::TypeCollector
  • Object
show all
Defined in:
lib/bigcommerce/prometheus/type_collectors/base.rb

Overview

Base type collector class

Direct Known Subclasses

Resque

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type: nil, default_labels: {}) ⇒ Base

Returns a new instance of Base.

Parameters:

  • type (String) (defaults to: nil)
  • default_labels (Hash) (defaults to: {})


31
32
33
34
35
36
# File 'lib/bigcommerce/prometheus/type_collectors/base.rb', line 31

def initialize(type: nil, default_labels: {})
  super()
  @type = type || self.class.to_s.downcase.gsub('::', '_').gsub('typecollector', '')
  @default_labels = default_labels || {}
  @metrics = build_metrics
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/bigcommerce/prometheus/type_collectors/base.rb', line 25

def type
  @type
end

Instance Method Details

#collect(data) ⇒ Object

Collect metrics from input data

Parameters:

  • data (Hash)


59
60
61
62
63
# File 'lib/bigcommerce/prometheus/type_collectors/base.rb', line 59

def collect(data)
  custom_labels = data.fetch('custom_labels', nil)
  labels = custom_labels.nil? ? @default_labels : @default_labels.merge(custom_labels)
  collect_metrics(data: data, labels: labels)
end

#metric(key) ⇒ Object

Parameters:

  • key (Symbol)


50
51
52
# File 'lib/bigcommerce/prometheus/type_collectors/base.rb', line 50

def metric(key)
  @metrics.fetch(key.to_sym, nil)
end

#metricsArray

Returns:

  • (Array)


41
42
43
44
45
# File 'lib/bigcommerce/prometheus/type_collectors/base.rb', line 41

def metrics
  return [] unless @metrics.any?

  @metrics.values
end