Class: SimpleBackup::Utils::Disk
- Inherits:
-
Object
- Object
- SimpleBackup::Utils::Disk
- Defined in:
- lib/simple_backup/utils/disk_usage.rb
Constant Summary collapse
- @@high_usage_treshold =
0.9
- @@paths =
[]
Class Method Summary collapse
- .add_path(path) ⇒ Object
- .high_usage_treshold ⇒ Object
- .high_usage_treshold=(value) ⇒ Object
- .usage ⇒ Object
Class Method Details
.add_path(path) ⇒ Object
17 18 19 |
# File 'lib/simple_backup/utils/disk_usage.rb', line 17 def self.add_path(path) @@paths << path unless @@paths.include?(path) end |
.high_usage_treshold ⇒ Object
13 14 15 |
# File 'lib/simple_backup/utils/disk_usage.rb', line 13 def self.high_usage_treshold @@high_usage_treshold end |
.high_usage_treshold=(value) ⇒ Object
7 8 9 10 11 |
# File 'lib/simple_backup/utils/disk_usage.rb', line 7 def self.high_usage_treshold=(value) @@high_usage_treshold = value.to_f raise ArgumentError.new "Backuper::Utils::Disk::high_usage_treshold must be a float greater than zero" if @@high_usage_treshold <= 0.0 end |
.usage ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/simple_backup/utils/disk_usage.rb', line 21 def self.usage df = `df -m #{@@paths.join(' ')} 2>/dev/null`.split("\n") df.shift max_percent = 0.0; df.map! do |row| row = row.split(' ') percent_usage = (row[4].gsub('%', '').to_f / 100).round(2) row = { mount: row[5], fs: row[0], size: row[1], used: row[2], available: row[3], percent: percent_usage, high_usage_exceeded: percent_usage >= @@high_usage_treshold } max_percent = row[:percent] if row[:percent] > max_percent row end { mounts: df.uniq, high_usage_exceeded: max_percent >= @@high_usage_treshold, high_usage: max_percent } end |