Class: Railswatch::Widgets::DiskUsage
- Inherits:
-
ResourceChart
- Object
- Base
- Chart
- ResourceChart
- Railswatch::Widgets::DiskUsage
- Defined in:
- lib/railswatch/widgets/resource_chart.rb
Instance Attribute Summary
Attributes inherited from ResourceChart
Attributes inherited from Chart
#description, #legend, #subtitle, #units
Attributes inherited from Base
Instance Method Summary collapse
- #format(measurement) ⇒ Object
-
#initialize(server) ⇒ DiskUsage
constructor
A new instance of DiskUsage.
- #measure ⇒ Object
Methods inherited from ResourceChart
Methods inherited from Chart
#data, #id, #to_partial_path, #type
Methods inherited from Base
Constructor Details
#initialize(server) ⇒ DiskUsage
Returns a new instance of DiskUsage.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/railswatch/widgets/resource_chart.rb', line 87 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
98 99 100 |
# File 'lib/railswatch/widgets/resource_chart.rb', line 98 def format(measurement) measurement['available'].to_f.round(2) end |
#measure ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/railswatch/widgets/resource_chart.rb', line 102 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 StandardError => e ::Rails.logger.error "Error fetching disk space: #{e.}" { available: 0, total: 0, used: 0 } end |