Class: ElasticAPM::Metrics::CpuMem::Linux::ProcStat Private

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

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.



125
126
127
# File 'lib/elastic_apm/metrics/cpu_mem.rb', line 125

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.



125
126
127
# File 'lib/elastic_apm/metrics/cpu_mem.rb', line 125

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.

rubocop:disable Metrics/MethodLength, Metrics/AbcSize



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/elastic_apm/metrics/cpu_mem.rb', line 128

def read!
  stat =
    IO.readlines('/proc/stat')
      .lazy
      .find { |sp| sp.start_with?('cpu ') }
      .split
      .map(&:to_i)[1..-1]

  user, nice, system, idle, iowait, irq, softirq, steal,
    _guest, _guest_nice = stat

  @total =
    user +
    nice +
    system +
    idle +
    iowait +
    irq +
    softirq +
    steal

  @usage = @total - (idle + iowait)

  self
end