Class: Datadog::Core::Telemetry::MetricsManager Private

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/core/telemetry/metrics_manager.rb

Overview

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.

MetricsManager aggregates and flushes metrics and distributions

API:

  • private

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregation_interval:, enabled:) ⇒ MetricsManager

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 MetricsManager.

API:

  • private



15
16
17
18
19
20
21
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 15

def initialize(aggregation_interval:, enabled:)
  @interval = aggregation_interval
  @enabled = enabled
  @mutex = Mutex.new

  @collections = {}
end

Instance Attribute Details

#collectionsObject (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.

API:

  • private



13
14
15
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 13

def collections
  @collections
end

#enabledObject (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.

API:

  • private



12
13
14
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 12

def enabled
  @enabled
end

Instance Method Details

#clearObject

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.

API:

  • private



74
75
76
77
78
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 74

def clear
  @mutex.synchronize do
    @collections = {}
  end
end

#dec(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.

API:

  • private



31
32
33
34
35
36
37
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 31

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: tags, common: common)
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.

API:

  • private



70
71
72
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 70

def disable!
  @enabled = false
end

#distribution(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.

API:

  • private



55
56
57
58
59
60
61
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 55

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: tags, common: common)
end

#flush!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.

API:

  • private



63
64
65
66
67
68
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 63

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

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.

API:

  • private



39
40
41
42
43
44
45
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 39

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: tags, common: common)
end

#inc(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.

API:

  • private



23
24
25
26
27
28
29
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 23

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: tags, common: common)
end

#rate(namespace, metric_name, value, tags: {}, common: true) ⇒ 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.

API:

  • private



47
48
49
50
51
52
53
# File 'lib/datadog/core/telemetry/metrics_manager.rb', line 47

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: tags, common: common)
end