Class: RailsServerMonitor::Warnings::LowMemoryComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/rails_server_monitor/warnings/low_memory_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ctx:) ⇒ LowMemoryComponent

Returns a new instance of LowMemoryComponent.



7
8
9
# File 'app/components/rails_server_monitor/warnings/low_memory_component.rb', line 7

def initialize(ctx:)
  @ctx = ctx
end

Instance Attribute Details

#ctxObject (readonly)

Returns the value of attribute ctx.



6
7
8
# File 'app/components/rails_server_monitor/warnings/low_memory_component.rb', line 6

def ctx
  @ctx
end

Instance Method Details

#configObject



19
20
21
# File 'app/components/rails_server_monitor/warnings/low_memory_component.rb', line 19

def config
  RailsServerMonitor.config
end

#max_memory_usageObject



23
24
25
# File 'app/components/rails_server_monitor/warnings/low_memory_component.rb', line 23

def max_memory_usage
  100 - config.low_memory_threshold
end

#scopeObject



11
12
13
14
15
16
17
# File 'app/components/rails_server_monitor/warnings/low_memory_component.rb', line 11

def scope
  @scope ||= RailsServerMonitor::ServerSnapshot
               .includes(:rails_server_monitor_server)
               .where("ram_usage_percentage >= ?", max_memory_usage)
               .where("created_at > ?", 3.days.ago)
               .limit(100)
end