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

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.



248
249
250
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 248

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.



248
249
250
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 248

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.



248
249
250
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 248

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



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'lib/atatus/metrics/cpu_mem_set.rb', line 251

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