Class: RailsErrorDashboard::Services::SystemHealthSnapshot

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/services/system_health_snapshot.rb

Overview

Pure algorithm: Capture runtime health metrics at error time

Captures GC stats, process RSS memory, thread count, connection pool stats, and Puma stats. NOT memoized — fresh data every call (unlike EnvironmentSnapshot). Every metric call individually wrapped in rescue => nil.

Safety contract (from HOST_APP_SAFETY.md):

  • Total snapshot < 1ms budget

  • NEVER ObjectSpace.each_object or ObjectSpace.count_objects (heap scan)

  • NEVER Thread.list.map(&:backtrace) (GVL hold)

  • Thread.list.count only (O(1), safe)

  • Process memory: Linux procfs ONLY, no fork/subprocess ever

  • No new gems, no global state, no Thread.current, no mutex

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.captureHash

Capture current system health metrics

Returns:

  • (Hash)

    Health snapshot (always safe, never raises)



21
22
23
24
25
26
# File 'lib/rails_error_dashboard/services/system_health_snapshot.rb', line 21

def self.capture
  new.capture
rescue => e
  RailsErrorDashboard::Logger.debug("[RailsErrorDashboard] SystemHealthSnapshot.capture failed: #{e.message}")
  { captured_at: Time.current.iso8601 }
end

Instance Method Details

#captureHash

Returns Health snapshot.

Returns:

  • (Hash)

    Health snapshot



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rails_error_dashboard/services/system_health_snapshot.rb', line 29

def capture
  {
    gc: gc_stats,
    process_memory_mb: process_memory_mb,
    thread_count: thread_count,
    connection_pool: connection_pool_stats,
    puma: puma_stats,
    job_queue: job_queue_stats,
    captured_at: Time.current.iso8601
  }
end