Module: InShape::Memory

Extended by:
ActionView::Helpers::NumberHelper
Defined in:
lib/inshape.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.max_usageObject

Returns the value of attribute max_usage.



12
13
14
# File 'lib/inshape.rb', line 12

def max_usage
  @max_usage
end

.min_freeObject

Returns the value of attribute min_free.



13
14
15
# File 'lib/inshape.rb', line 13

def min_free
  @min_free
end

Class Method Details

.statusObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/inshape.rb', line 15

def status
  if RUBY_ENGINE == 'jruby'

    # java.lang.System.gc
    rt  = java.lang.Runtime.getRuntime
    max = rt.maxMemory
    allocated = rt.totalMemory
    free = rt.freeMemory
    used = (allocated - free)
    usage = (used / max.to_f)
    is_ok = usage < max_usage && free >= min_free

    OpenStruct.new is_ok: is_ok, content: {
      memory: { Max: number_to_human_size(max),
                Allocated: number_to_human_size(allocated),
                Used: number_to_human_size(used),
                Usage: usage.round(2),
                OK?: is_ok } }.with_indifferent_access.as_json
  else

    OpenStruct.new is_ok: true, content: {}

  end
end