class ElasticAPM::Metrics::CpuMem
@api private
def collect
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
def initialize(config)
def initialize(config) @config = config @sampler = sampler_for_platform(Metrics.platform) end
def sample
def sample @sampler.sample end
def sampler_for_platform(platform)
def sampler_for_platform(platform) case platform when :linux then Linux.new else warn "Unsupported platform '#{platform}' - Disabling metrics" @disabled = true nil end end