Class: Bigcommerce::Prometheus::TypeCollectors::Base
- Inherits:
-
PrometheusExporter::Server::TypeCollector
- Object
- PrometheusExporter::Server::TypeCollector
- Bigcommerce::Prometheus::TypeCollectors::Base
- Defined in:
- lib/bigcommerce/prometheus/type_collectors/base.rb
Overview
Base type collector class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#collect(data) ⇒ Object
Collect metrics from input data.
-
#initialize(type: nil, default_labels: {}) ⇒ Base
constructor
A new instance of Base.
- #metric(key) ⇒ Object
- #metrics ⇒ Array
Constructor Details
#initialize(type: nil, default_labels: {}) ⇒ Base
Returns a new instance of Base.
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
#type ⇒ Object (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
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
50 51 52 |
# File 'lib/bigcommerce/prometheus/type_collectors/base.rb', line 50 def metric(key) @metrics.fetch(key.to_sym, nil) end |
#metrics ⇒ 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 |