in lib/elastic_apm/metrics/cpu_mem_set.rb [162:189]
def read!
stat =
IO.readlines('/proc/stat')
.lazy
.find { |sp| sp.start_with?('cpu ') }
.split
.map(&:to_i)[1..-1]
values =
CPU_FIELDS.each_with_index.each_with_object({}) do |(key, i), v|
v[key] = stat[i] || 0
end
@total =
values[:user] +
values[:nice] +
values[:system] +
values[:idle] +
values[:iowait] +
values[:irq] +
values[:softirq] +
values[:steal]
@usage = @total - (values[:idle] + values[:iowait])
self
end