Class: Datadog::Runtime::Metrics
- Defined in:
- lib/ddtrace/runtime/metrics.rb
Overview
For generating runtime metrics
Constant Summary
Constants included from Metrics::Options
Instance Attribute Summary
Attributes inherited from Metrics
Instance Method Summary collapse
- #associate_with_span(span) ⇒ Object
- #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
#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.
13 14 15 16 17 18 19 20 |
# File 'lib/ddtrace/runtime/metrics.rb', line 13 def initialize( = {}) super # Initialize service list @services = Set.new(.fetch(:services, [])) @service_tags = nil end |
Instance Method Details
#associate_with_span(span) ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/ddtrace/runtime/metrics.rb', line 22 def associate_with_span(span) return if !enabled? || span.nil? # Register service as associated with metrics register_service(span.service) unless span.service.nil? # Tag span with language and runtime ID for association with metrics span.set_tag(Ext::Runtime::TAG_LANG, Runtime::Identity.lang) end |
#default_metric_options ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ddtrace/runtime/metrics.rb', line 70 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
48 49 50 51 52 53 54 |
# File 'lib/ddtrace/runtime/metrics.rb', line 48 def flush return unless enabled? try_flush { gauge(Ext::Runtime::Metrics::METRIC_CLASS_COUNT, ClassCount.value) if ClassCount.available? } try_flush { gauge(Ext::Runtime::Metrics::METRIC_THREAD_COUNT, ThreadCount.value) if ThreadCount.available? } try_flush { gc_metrics.each { |metric, value| gauge(metric, value) } if GC.available? } end |
#gc_metrics ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/ddtrace/runtime/metrics.rb', line 56 def gc_metrics Hash[ GC.stat.flat_map do |k, v| nested_gc_metric(Ext::Runtime::Metrics::METRIC_GC_PREFIX, k, v) end ] end |
#register_service(service) ⇒ Object
Associate service with runtime metrics
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ddtrace/runtime/metrics.rb', line 33 def register_service(service) return if !enabled? || service.nil? service = service.to_s unless @services.include?(service) # Add service to list and update services tag services << service # Recompile the service tags end end |