class ElasticAPM::Metrics::CpuMem
@api private
Attributes
config[R]
sampler[R]
Public Class Methods
new(config)
click to toggle source
# File lib/elastic_apm/metrics/cpu_mem.rb, line 48 def initialize(config) @config = config @sampler = sampler_for_platform(Metrics.platform) end
Public Instance Methods
collect()
click to toggle source
rubocop:disable Metrics/MethodLength, Metrics/AbcSize
# File lib/elastic_apm/metrics/cpu_mem.rb, line 60 def collect return unless sampler current = sample unless @previous @previous = current return end delta = current.delta(@previous) cpu_usage_pct = delta.system_cpu_usage.to_f / delta.system_cpu_total cpu_process_pct = delta.process_cpu_usage.to_f / delta.system_cpu_total @previous = current { 'system.cpu.total.norm.pct': cpu_usage_pct, 'system.memory.actual.free': current.system_memory_free, 'system.memory.total': current.system_memory_total, 'system.process.cpu.total.norm.pct': cpu_process_pct, 'system.process.memory.size': current.process_memory_size, 'system.process.memory.rss.bytes': current.process_memory_rss * current.page_size } end
sample()
click to toggle source
# File lib/elastic_apm/metrics/cpu_mem.rb, line 55 def sample @sampler.sample end
Private Instance Methods
sampler_for_platform(platform)
click to toggle source
rubocop:enable Metrics/MethodLength, Metrics/AbcSize
# File lib/elastic_apm/metrics/cpu_mem.rb, line 91 def sampler_for_platform(platform) case platform when :linux then Linux.new else warn "Unsupported platform '#{platform}' - Disabling metrics" @disabled = true nil end end