class CloudWatchMetrics::Linux::MemInfo

Constants

PATH

Attributes

time[R]

Public Class Methods

new() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 10
def initialize
  @time = Time.now
  @data = File.readlines(PATH)
    .map { |line| /^([^:]+):\s+(\d+)/.match(line)&.captures }
    .compact
    .map { |key, value| [key, value.to_i] }
    .to_h
end

Public Instance Methods

buffers() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 31
def buffers
  @data.fetch('Buffers')
end
cached() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 27
def cached
  @data.fetch('Cached')
end
mem_avail() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 43
def mem_avail
  mem_free + cached + buffers
end
mem_free() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 23
def mem_free
  @data.fetch('MemFree')
end
mem_total() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 19
def mem_total
  @data.fetch('MemTotal')
end
mem_used() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 47
def mem_used
  mem_total - mem_avail
end
mem_util() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 51
def mem_util
  mem_used.to_f / mem_total
end
swap?() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 55
def swap?
  swap_total.positive?
end
swap_free() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 39
def swap_free
  @data.fetch('SwapFree')
end
swap_total() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 35
def swap_total
  @data.fetch('SwapTotal')
end
swap_used() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 59
def swap_used
  swap_total - swap_free
end
swap_util() click to toggle source
# File lib/cloud_watch_metrics/linux/meminfo.rb, line 63
def swap_util
  swap_used.to_f / swap_total
end