Class: RorVsWild::Metrics::Memory

Inherits:
Object
  • Object
show all
Defined in:
lib/rorvswild/metrics/memory.rb

Constant Summary collapse

PROC_MEMINFO =
"/proc/meminfo".freeze
MEM_TOTAL =

Total usable RAM (i.e., physical RAM minus a few reserved bits and the kernel binary code).

"MemTotal"
MEM_FREE =

The sum of LowFree+HighFree.

"MemFree"
MEM_AVAILABLE =

An estimate of how much memory is available for starting new applications, without swapping.

"MemAvailable"
BUFFERS =

Relatively temporary storage for raw disk blocks that shouldn’t get tremendously large (20MB or so).

"Buffers"
CACHED =

In-memory cache for files read from the disk (the page cache). Doesn’t include SwapCached.

"Cached"
SWAP_TOTAL =

Total amount of swap space available.

"SwapTotal"
SWAP_FREE =

Amount of swap space that is currently unused.

"SwapFree"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ram_availableObject (readonly)

Returns the value of attribute ram_available.



4
5
6
# File 'lib/rorvswild/metrics/memory.rb', line 4

def ram_available
  @ram_available
end

#ram_buffersObject (readonly)

Returns the value of attribute ram_buffers.



4
5
6
# File 'lib/rorvswild/metrics/memory.rb', line 4

def ram_buffers
  @ram_buffers
end

#ram_cachedObject (readonly)

Returns the value of attribute ram_cached.



4
5
6
# File 'lib/rorvswild/metrics/memory.rb', line 4

def ram_cached
  @ram_cached
end

#ram_freeObject (readonly)

Returns the value of attribute ram_free.



4
5
6
# File 'lib/rorvswild/metrics/memory.rb', line 4

def ram_free
  @ram_free
end

#ram_totalObject (readonly)

Returns the value of attribute ram_total.



4
5
6
# File 'lib/rorvswild/metrics/memory.rb', line 4

def ram_total
  @ram_total
end

#storage_totalObject (readonly)

Returns the value of attribute storage_total.



6
7
8
# File 'lib/rorvswild/metrics/memory.rb', line 6

def storage_total
  @storage_total
end

#storage_usedObject (readonly)

Returns the value of attribute storage_used.



6
7
8
# File 'lib/rorvswild/metrics/memory.rb', line 6

def storage_used
  @storage_used
end

#swap_freeObject (readonly)

Returns the value of attribute swap_free.



5
6
7
# File 'lib/rorvswild/metrics/memory.rb', line 5

def swap_free
  @swap_free
end

#swap_totalObject (readonly)

Returns the value of attribute swap_total.



5
6
7
# File 'lib/rorvswild/metrics/memory.rb', line 5

def swap_total
  @swap_total
end

Instance Method Details

#ram_usedObject



8
9
10
# File 'lib/rorvswild/metrics/memory.rb', line 8

def ram_used
  ram_total - ram_available
end

#swap_usedObject



12
13
14
# File 'lib/rorvswild/metrics/memory.rb', line 12

def swap_used
  swap_total - swap_free
end

#updateObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/rorvswild/metrics/memory.rb', line 25

def update
  return unless info = read_meminfo
  @ram_total = convert_to_bytes(info[MEM_TOTAL])
  @ram_free = convert_to_bytes(info[MEM_FREE])
  @ram_available = convert_to_bytes(info[MEM_AVAILABLE])
  @ram_buffers = convert_to_bytes(info[BUFFERS])
  @ram_cached = convert_to_bytes(info[CACHED])
  @swap_total = convert_to_bytes(info[SWAP_TOTAL])
  @swap_free = convert_to_bytes(info[SWAP_FREE])
end