Class: Yabeda::Metric
- Inherits:
-
Object
- Object
- Yabeda::Metric
- Extended by:
- Dry::Initializer
- Defined in:
- lib/yabeda/metric.rb
Overview
Base class for all metrics
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
private
Redefined option reader to get group-level adapter if not set on metric level.
-
#aggregation ⇒ Object
readonly
How adapters should aggregate values from different processes.
-
#comment ⇒ Object
readonly
Documentation string.
-
#group ⇒ Object
readonly
Category name for grouping metrics.
-
#name ⇒ Object
readonly
Metric name.
-
#per ⇒ Object
readonly
Per which unit is measured ‘unit`.
-
#tags ⇒ Array<Symbol>
readonly
Returns allowed tags for metric (with account for global and group-level
default_tags
). -
#unit ⇒ Object
readonly
In which units it is measured.
Instance Method Summary collapse
-
#adapters ⇒ Hash<Symbol, Yabeda::BaseAdapter>
Returns the metric adapters.
-
#get(labels = {}) ⇒ Object
Returns the value for the given label set.
- #initialize(name, **options) ⇒ Object constructor
- #inspect ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(name, **options) ⇒ Object
Instance Attribute Details
#adapter ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Redefined option reader to get group-level adapter if not set on metric level
18 |
# File 'lib/yabeda/metric.rb', line 18 option :adapter, optional: true, comment: "Monitoring system adapter to register metric in and report metric values to (other adapters won't be used)" |
#aggregation ⇒ Object (readonly)
How adapters should aggregate values from different processes
Reader method for the aggregation
initializer parameter.
16 |
# File 'lib/yabeda/metric.rb', line 16 option :aggregation, optional: true, comment: "How adapters should aggregate values from different processes" |
#comment ⇒ Object (readonly)
Documentation string. Required by some adapters.
Reader method for the comment
initializer parameter.
11 |
# File 'lib/yabeda/metric.rb', line 11 option :comment, optional: true, comment: "Documentation string. Required by some adapters." |
#group ⇒ Object (readonly)
Category name for grouping metrics
Reader method for the group
initializer parameter.
15 |
# File 'lib/yabeda/metric.rb', line 15 option :group, optional: true, comment: "Category name for grouping metrics" |
#name ⇒ Object (readonly)
Metric name. Use snake_case. E.g. job_runtime
Reader method for the name
initializer parameter.
10 |
# File 'lib/yabeda/metric.rb', line 10 param :name, comment: "Metric name. Use snake_case. E.g. job_runtime" |
#per ⇒ Object (readonly)
Per which unit is measured ‘unit`. E.g. `call` as in seconds per call
Reader method for the per
initializer parameter.
14 |
# File 'lib/yabeda/metric.rb', line 14 option :per, optional: true, comment: "Per which unit is measured `unit`. E.g. `call` as in seconds per call" |
#tags ⇒ Array<Symbol> (readonly)
Returns allowed tags for metric (with account for global and group-level default_tags
)
32 |
# File 'lib/yabeda/metric.rb', line 32 option :tags, optional: true, comment: "Allowed labels to be set. Required by some adapters." |
#unit ⇒ Object (readonly)
In which units it is measured. E.g. ‘seconds`
Reader method for the unit
initializer parameter.
13 |
# File 'lib/yabeda/metric.rb', line 13 option :unit, optional: true, comment: "In which units it is measured. E.g. `seconds`" |
Instance Method Details
#adapters ⇒ Hash<Symbol, Yabeda::BaseAdapter>
Returns the metric adapters
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/yabeda/metric.rb', line 42 def adapters return ::Yabeda.adapters unless adapter @adapters ||= begin adapter_names = Array(adapter) unknown_adapters = adapter_names - ::Yabeda.adapters.keys if unknown_adapters.any? raise ConfigurationError, "invalid adapter option #{adapter.inspect} in metric #{inspect}" end ::Yabeda.adapters.slice(*adapter_names) end end |
#get(labels = {}) ⇒ Object
Returns the value for the given label set
22 23 24 |
# File 'lib/yabeda/metric.rb', line 22 def get(labels = {}) values[::Yabeda::Tags.build(labels, group)] end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/yabeda/metric.rb', line 36 def inspect "#<#{self.class.name}: #{[@group, @name].compact.join('.')}>" end |
#values ⇒ Object
26 27 28 |
# File 'lib/yabeda/metric.rb', line 26 def values @values ||= Concurrent::Hash.new end |