Class: ElasticAPM::Metrics::CpuMemSet::Linux::ProcStat Private

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_apm/metrics/cpu_mem_set.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Constant Summary collapse

CPU_FIELDS =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

%i[
  user
  nice
  system
  idle
  iowait
  irq
  softirq
  steal
  guest
  guest_nice
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#totalObject (readonly)

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.


149
150
151
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 149

def total
  @total
end

#usageObject (readonly)

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.


149
150
151
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 149

def usage
  @usage
end

Instance Method Details

#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.

[View source]

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