Sha256: 9e322810cdb99c4e5b80c3b863dc1d4401ae2e290128e7643b3a195714789f86

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module ElasticAPM
  module Metrics
    # @api private
    class VMSet < Set
      include Logging

      def collect
        read!
        super
      end

      # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
      def read!
        return if disabled?

        stat = GC.stat

        gauge(:'ruby.gc.count').value = stat[:count]
        gauge(:'ruby.threads').value = Thread.list.count
        gauge(:'ruby.heap.slots.live').value = stat[:heap_live_slots]

        gauge(:'ruby.heap.slots.free').value = stat[:heap_free_slots]
        gauge(:'ruby.heap.allocations.total').value =
          stat[:total_allocated_objects]

        return unless GC::Profiler.enabled?

        @total_time ||= 0
        @total_time += GC::Profiler.total_time
        GC::Profiler.clear
        gauge(:'ruby.gc.time').value = @total_time
      rescue TypeError => e
        error 'VM metrics encountered error: %s', e
        debug('Backtrace:') { e.backtrace.join("\n") }

        disable!
      end

      # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elastic-apm-3.2.0 lib/elastic_apm/metrics/vm_set.rb