Class: Atatus::Metrics::CpuMemSet::Linux::ProcStat Private

Inherits:
Object
  • Object
show all
Defined in:
lib/atatus/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.



178
179
180
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 178

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.



178
179
180
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 178

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.



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 192

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