Class: Datadog::Core::Telemetry::MetricsCollection
- Inherits:
-
Object
- Object
- Datadog::Core::Telemetry::MetricsCollection
- Defined in:
- lib/datadog/core/telemetry/metrics_collection.rb
Overview
MetricsCollection is a thread-safe collection of metrics per namespace
Instance Attribute Summary collapse
-
#interval ⇒ Object
readonly
Returns the value of attribute interval.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
Instance Method Summary collapse
- #dec(metric_name, value, tags: {}, common: true) ⇒ Object
- #distribution(metric_name, value, tags: {}, common: true) ⇒ Object
- #flush! ⇒ Object
- #gauge(metric_name, value, tags: {}, common: true) ⇒ Object
- #inc(metric_name, value, tags: {}, common: true) ⇒ Object
-
#initialize(namespace, aggregation_interval:) ⇒ MetricsCollection
constructor
A new instance of MetricsCollection.
- #rate(metric_name, value, tags: {}, common: true) ⇒ Object
Constructor Details
#initialize(namespace, aggregation_interval:) ⇒ MetricsCollection
Returns a new instance of MetricsCollection.
13 14 15 16 17 18 19 20 21 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 13 def initialize(namespace, aggregation_interval:) @namespace = namespace @interval = aggregation_interval @mutex = Mutex.new @metrics = {} @distributions = {} end |
Instance Attribute Details
#interval ⇒ Object (readonly)
Returns the value of attribute interval.
11 12 13 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 11 def interval @interval end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
11 12 13 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 11 def namespace @namespace end |
Instance Method Details
#dec(metric_name, value, tags: {}, common: true) ⇒ Object
28 29 30 31 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 28 def dec(metric_name, value, tags: {}, common: true) metric = Metric::Count.new(metric_name, tags: , common: common) fetch_or_add_metric(metric, -value) end |
#distribution(metric_name, value, tags: {}, common: true) ⇒ Object
43 44 45 46 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 43 def distribution(metric_name, value, tags: {}, common: true) metric = Metric::Distribution.new(metric_name, tags: , common: common) fetch_or_add_distribution(metric, value) end |
#flush! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 48 def flush! @mutex.synchronize do events = [] events << Event::GenerateMetrics.new(@namespace, @metrics.values) if @metrics.any? events << Event::Distributions.new(@namespace, @distributions.values) if @distributions.any? @metrics = {} @distributions = {} events end end |
#gauge(metric_name, value, tags: {}, common: true) ⇒ Object
33 34 35 36 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 33 def gauge(metric_name, value, tags: {}, common: true) metric = Metric::Gauge.new(metric_name, tags: , common: common, interval: @interval) fetch_or_add_metric(metric, value) end |
#inc(metric_name, value, tags: {}, common: true) ⇒ Object
23 24 25 26 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 23 def inc(metric_name, value, tags: {}, common: true) metric = Metric::Count.new(metric_name, tags: , common: common) fetch_or_add_metric(metric, value) end |
#rate(metric_name, value, tags: {}, common: true) ⇒ Object
38 39 40 41 |
# File 'lib/datadog/core/telemetry/metrics_collection.rb', line 38 def rate(metric_name, value, tags: {}, common: true) metric = Metric::Rate.new(metric_name, tags: , common: common, interval: @interval) fetch_or_add_metric(metric, value) end |