Class: ElasticAPM::Metrics::Set Private
- Inherits:
-
Object
- Object
- ElasticAPM::Metrics::Set
- Includes:
- Logging
- Defined in:
- lib/elastic_apm/metrics/set.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Direct Known Subclasses
Constant Summary collapse
- DISTINCT_LABEL_LIMIT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
1000
Constants included from Logging
Logging::LEVELS, Logging::PREFIX
Instance Attribute Summary collapse
- #metrics ⇒ Object readonly private
Instance Method Summary collapse
- #collect ⇒ Object private
- #counter(key, tags: nil, **args) ⇒ Object private
- #disable! ⇒ Object private
- #disabled? ⇒ Boolean private
- #gauge(key, tags: nil, **args) ⇒ Object private
-
#initialize(config) ⇒ Set
constructor
private
A new instance of Set.
- #metric(kls, key, tags: nil, **args) ⇒ Object private
- #timer(key, tags: nil, **args) ⇒ Object private
Methods included from Logging
#debug, #error, #fatal, #info, #warn
Constructor Details
#initialize(config) ⇒ Set
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.
Returns a new instance of Set.
31 32 33 34 35 36 |
# File 'lib/elastic_apm/metrics/set.rb', line 31 def initialize(config) @config = config @metrics = {} @disabled = false @lock = Mutex.new end |
Instance Attribute Details
#metrics ⇒ 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.
38 39 40 |
# File 'lib/elastic_apm/metrics/set.rb', line 38 def metrics @metrics end |
Instance Method Details
#collect ⇒ Object
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.
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/elastic_apm/metrics/set.rb', line 88 def collect return if disabled? @lock.synchronize do metrics.each_with_object({}) do |(key, metric), sets| next unless (value = metric.collect) # metrics have a key of name and flat array of key-value pairs # eg [name, key, value, key, value] # they can be sent in the same metricset but not if they have # differing tags. So, we split the resulting sets by tags first. name, * = key sets[] ||= Metricset.new # then we set the `samples` value for the metricset set = sets[] set.samples[name] = value # and finally we copy the tags from the Metric to the Metricset set. metric. end.values end end |
#counter(key, tags: nil, **args) ⇒ Object
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.
48 49 50 |
# File 'lib/elastic_apm/metrics/set.rb', line 48 def counter(key, tags: nil, **args) metric(Counter, key, tags: , **args) end |
#disable! ⇒ Object
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.
40 41 42 |
# File 'lib/elastic_apm/metrics/set.rb', line 40 def disable! @disabled = true end |
#disabled? ⇒ Boolean
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.
44 45 46 |
# File 'lib/elastic_apm/metrics/set.rb', line 44 def disabled? @disabled end |
#gauge(key, tags: nil, **args) ⇒ Object
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.
52 53 54 |
# File 'lib/elastic_apm/metrics/set.rb', line 52 def gauge(key, tags: nil, **args) metric(Gauge, key, tags: , **args) end |
#metric(kls, key, tags: nil, **args) ⇒ Object
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.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/elastic_apm/metrics/set.rb', line 60 def metric(kls, key, tags: nil, **args) if @config.disable_metrics.any? { |p| p.match? key } return NOOP end key = (key, ) return metrics[key] if metrics[key] @lock.synchronize do return metrics[key] if metrics[key] metrics[key] = if metrics.length < DISTINCT_LABEL_LIMIT kls.new(key, tags: , **args) else unless @label_limit_logged warn( 'The limit of %d metricsets has been reached, no new ' \ 'metricsets will be created.', DISTINCT_LABEL_LIMIT ) @label_limit_logged = true end NOOP end end end |
#timer(key, tags: nil, **args) ⇒ Object
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.
56 57 58 |
# File 'lib/elastic_apm/metrics/set.rb', line 56 def timer(key, tags: nil, **args) metric(Timer, key, tags: , **args) end |