class ElasticAPM::Metrics::CpuMemSet
@api private
def calculate_deltas(current, previous)
def calculate_deltas(current, previous) system_cpu_total = current.system_cpu_total - previous.system_cpu_total system_cpu_usage = current.system_cpu_usage - previous.system_cpu_usage process_cpu_usage = current.process_cpu_usage - previous.process_cpu_usage cpu_usage_pct = system_cpu_usage.to_f / system_cpu_total cpu_process_pct = process_cpu_usage.to_f / system_cpu_total [cpu_usage_pct, cpu_process_pct] end
def collect
def collect read! super end
def initialize(config)
def initialize(config) super @sampler = sampler_for_platform(Metrics.platform) read! # set @previous on boot end
def read!
def read! return if disabled? current = @sampler.sample unless @previous @previous = current return end cpu_usage_pct, cpu_process_pct = calculate_deltas(current, @previous) gauge(:'system.cpu.total.norm.pct').value = cpu_usage_pct gauge(:'system.memory.actual.free').value = current.system_memory_free gauge(:'system.memory.total').value = current.system_memory_total gauge(:'system.process.cpu.total.norm.pct').value = cpu_process_pct gauge(:'system.process.memory.size').value = current.process_memory_size gauge(:'system.process.memory.rss.bytes').value = current.process_memory_rss * current.page_size @previous = current end
def sampler_for_platform(platform)
def sampler_for_platform(platform) case platform when :linux then Linux.new else warn "Disabling system metrics, unsupported platform '#{platform}'" disable! nil end end