Class: Datadog::Core::Runtime::Metrics
- Inherits:
-
Metrics::Client
- Object
- Metrics::Client
- Datadog::Core::Runtime::Metrics
- Defined in:
- lib/datadog/core/runtime/metrics.rb
Overview
For generating runtime metrics
Constant Summary
Constants included from Metrics::Options
Instance Attribute Summary
Attributes inherited from Metrics::Client
Instance Method Summary collapse
- #default_metric_options ⇒ Object
-
#flush ⇒ Object
Flush all runtime metrics to Statsd client.
- #gc_metrics ⇒ Object
-
#initialize(**options) ⇒ Metrics
constructor
A new instance of Metrics.
-
#register_service(service) ⇒ Object
Associate service with runtime metrics.
- #try_flush ⇒ Object
Methods inherited from Metrics::Client
#close, #configure, #count, #default_hostname, #default_port, #default_statsd_client, #distribution, #enabled=, #enabled?, #gauge, #increment, #send_metrics, #send_stats?, #supported?, #time
Methods included from Metrics::Options
Constructor Details
#initialize(**options) ⇒ Metrics
Returns a new instance of Metrics.
14 15 16 17 18 19 20 21 |
# File 'lib/datadog/core/runtime/metrics.rb', line 14 def initialize(**) super # Initialize service list @services = Set.new(.fetch(:services, [])) @service_tags = nil end |
Instance Method Details
#default_metric_options ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/datadog/core/runtime/metrics.rb', line 95 def # Return dupes, so that the constant isn't modified, # and defaults are unfrozen for mutation in Statsd. super.tap do || [:tags] = [:tags].dup # Add services dynamically because they might change during runtime. [:tags].concat() unless .nil? end end |
#flush ⇒ Object
Flush all runtime metrics to Statsd client
#gc_metrics ⇒ Object
83 84 85 86 87 |
# File 'lib/datadog/core/runtime/metrics.rb', line 83 def gc_metrics Core::Environment::GC.stat.flat_map do |k, v| nested_gc_metric(Core::Runtime::Ext::Metrics::METRIC_GC_PREFIX, k, v) end.to_h end |
#register_service(service) ⇒ Object
Associate service with runtime metrics
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/datadog/core/runtime/metrics.rb', line 24 def register_service(service) return unless enabled? && service service = service.to_s unless @services.include?(service) # Add service to list and update services tag services << service # Recompile the service tags end end |
#try_flush ⇒ Object
89 90 91 92 93 |
# File 'lib/datadog/core/runtime/metrics.rb', line 89 def try_flush yield rescue StandardError => e Datadog.logger.error("Error while sending runtime metric. Cause: #{e.class.name} #{e.}") end |