Class: RailsPerformance::SystemMonitor::DiskUsage

Inherits:
ResourceChart
  • Object
show all
Defined in:
lib/rails_performance/system_monitor/resource_chart.rb

Instance Attribute Summary

Attributes inherited from ResourceChart

#description, #key, #legend, #server, #subtitle, #type

Instance Method Summary collapse

Methods inherited from ResourceChart

#data, #id, #signal

Constructor Details

#initialize(server) ⇒ DiskUsage

Returns a new instance of DiskUsage.



76
77
78
79
80
81
82
83
84
85
# File 'lib/rails_performance/system_monitor/resource_chart.rb', line 76

def initialize server
  super(
    server:,
    key: :disk,
    type: "Usage",
    subtitle: "Storage",
    description: "Available storage size (local disk size)",
    legend: "Usage",
  )
end

Instance Method Details

#format(measurement) ⇒ Object



87
88
89
# File 'lib/rails_performance/system_monitor/resource_chart.rb', line 87

def format measurement
  measurement["available"].to_f.round(2)
end

#measureObject



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/rails_performance/system_monitor/resource_chart.rb', line 91

def measure
  path = "/"
  stat = Sys::Filesystem.stat(path)
  {
    available: stat.blocks_available * stat.block_size,
    total: stat.blocks * stat.block_size,
    used: (stat.blocks - stat.blocks_available) * stat.block_size
  }
rescue => e
  ::Rails.logger.error "Error fetching disk space: #{e.message}"
  {available: 0, total: 0, used: 0}
end