Method: ElasticAPM::Metrics::CpuMemSet::Linux::ProcStat#read!
- Defined in:
- lib/elastic_apm/metrics/cpu_mem_set.rb
#read! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 163 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 |