Class: Railswatch::Widgets::DiskUsage

Inherits:
ResourceChart show all
Defined in:
lib/railswatch/widgets/resource_chart.rb

Instance Attribute Summary

Attributes inherited from ResourceChart

#key, #server, #type

Attributes inherited from Chart

#description, #legend, #subtitle, #units

Attributes inherited from Base

#datasource

Instance Method Summary collapse

Methods inherited from ResourceChart

#data, #id, #signal

Methods inherited from Chart

#data, #id, #to_partial_path, #type

Methods inherited from Base

#to_partial_path

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

#measureObject



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.message}"
  { available: 0, total: 0, used: 0 }
end