Class: ElasticAPM::Metrics::CpuMemSet::Linux::Meminfo 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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

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



219
220
221
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 219

def available
  @available
end

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



219
220
221
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 219

def page_size
  @page_size
end

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



219
220
221
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 219

def total
  @total
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/PerceivedComplexity rubocop:disable Metrics/CyclomaticComplexity



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/elastic_apm/metrics/cpu_mem_set.rb', line 223

def read!
  # rubocop:disable Style/RescueModifier
  @page_size = `getconf PAGESIZE`.chomp.to_i rescue 4096
  # rubocop:enable Style/RescueModifier

  info =
    IO.readlines('/proc/meminfo')
      .lazy
      .each_with_object({}) do |line, hsh|
        if line.start_with?('MemTotal:')
          hsh[:total] = line.split[1].to_i * 1024
        elsif line.start_with?('MemAvailable:')
          hsh[:available] = line.split[1].to_i * 1024
        elsif line.start_with?('MemFree:')
          hsh[:free] = line.split[1].to_i * 1024
        elsif line.start_with?('Buffers:')
          hsh[:buffers] = line.split[1].to_i * 1024
        elsif line.start_with?('Cached:')
          hsh[:cached] = line.split[1].to_i * 1024
        end

        break hsh if hsh[:total] && hsh[:available]
      end

  @total = info[:total]
  @available =
    info[:available] || info[:free] + info[:buffers] + info[:cached]

  self
end