Class: SolidObserver::StorageInfo

Inherits:
BaseEvent
  • Object
show all
Defined in:
app/models/solid_observer/storage_info.rb

Constant Summary collapse

MB_TO_BYTES =
1_048_576
GB_TO_BYTES =
1_073_741_824

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.record_snapshot(db_size:, event_count:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'app/models/solid_observer/storage_info.rb', line 17

def self.record_snapshot(db_size:, event_count:)
  create!(
    db_size_bytes: db_size || 0,
    event_count: event_count,
    recorded_at: Time.current
  )
rescue ActiveRecord::RecordInvalid => e
  Rails.logger.error "[SolidObserver] Failed to record storage snapshot: #{e.message}"
  raise
end

Instance Method Details

#db_size_gbObject



32
33
34
# File 'app/models/solid_observer/storage_info.rb', line 32

def db_size_gb
  (db_size_bytes / GB_TO_BYTES.to_f).round(2)
end

#db_size_mbObject



28
29
30
# File 'app/models/solid_observer/storage_info.rb', line 28

def db_size_mb
  (db_size_bytes / MB_TO_BYTES.to_f).round(2)
end