Class: Datadog::Core::Telemetry::MetricsManager
- Inherits:
-
Object
- Object
- Datadog::Core::Telemetry::MetricsManager
- Defined in:
- lib/datadog/core/telemetry/metrics_manager.rb
Overview
MetricsManager aggregates and flushes metrics and distributions
Instance Attribute Summary collapse
-
#enabled ⇒ Object
readonly
Returns the value of attribute enabled.
Instance Method Summary collapse
- #dec(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
- #disable! ⇒ Object
- #distribution(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
- #flush! ⇒ Object
- #gauge(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
- #inc(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
-
#initialize(aggregation_interval:, enabled:) ⇒ MetricsManager
constructor
A new instance of MetricsManager.
- #rate(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
Constructor Details
#initialize(aggregation_interval:, enabled:) ⇒ MetricsManager
Returns a new instance of MetricsManager.
12 13 14 15 16 17 18 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 12 def initialize(aggregation_interval:, enabled:) @interval = aggregation_interval @enabled = enabled @mutex = Mutex.new @collections = {} end |
Instance Attribute Details
#enabled ⇒ Object (readonly)
Returns the value of attribute enabled.
10 11 12 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 10 def enabled @enabled end |
Instance Method Details
#dec(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 28 def dec(namespace, metric_name, value, tags: {}, common: true) return unless @enabled # collection is thread-safe internally collection = fetch_or_create_collection(namespace) collection.dec(metric_name, value, tags: , common: common) end |
#disable! ⇒ Object
67 68 69 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 67 def disable! @enabled = false end |
#distribution(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 52 def distribution(namespace, metric_name, value, tags: {}, common: true) return unless @enabled # collection is thread-safe internally collection = fetch_or_create_collection(namespace) collection.distribution(metric_name, value, tags: , common: common) end |
#flush! ⇒ Object
60 61 62 63 64 65 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 60 def flush! return [] unless @enabled collections = @mutex.synchronize { @collections.values } collections.reduce([]) { |events, collection| events + collection.flush! } end |
#gauge(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 36 def gauge(namespace, metric_name, value, tags: {}, common: true) return unless @enabled # collection is thread-safe internally collection = fetch_or_create_collection(namespace) collection.gauge(metric_name, value, tags: , common: common) end |
#inc(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 20 def inc(namespace, metric_name, value, tags: {}, common: true) return unless @enabled # collection is thread-safe internally collection = fetch_or_create_collection(namespace) collection.inc(metric_name, value, tags: , common: common) end |
#rate(namespace, metric_name, value, tags: {}, common: true) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 44 def rate(namespace, metric_name, value, tags: {}, common: true) return unless @enabled # collection is thread-safe internally collection = fetch_or_create_collection(namespace) collection.rate(metric_name, value, tags: , common: common) end |