Class: Doctor::HdAnalyser

Inherits:
Object
  • Object
show all
Defined in:
app/analyser/doctor/hd_analyser.rb

Instance Method Summary collapse

Instance Method Details

#analyseObject



5
6
7
8
9
10
11
12
13
# File 'app/analyser/doctor/hd_analyser.rb', line 5

def analyse
  result = []

  Doctor::ConfigManager.directory_list.each { |directory|
    result << validate_free_space(directory)
  }

  result
end

#get_used_space(path) ⇒ Object



35
36
37
38
39
40
# File 'app/analyser/doctor/hd_analyser.rb', line 35

def get_used_space(path)
  stat = Sys::Filesystem.stat(path)
  free_space = (stat.block_size * stat.blocks_available) / 1024 / 1024 / 1024
  total_space = (stat.block_size * stat.blocks) / 1024 / 1024 / 1024
  (total_space - free_space) * 100 / total_space
end

#validate_free_space(directory) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/analyser/doctor/hd_analyser.rb', line 15

def validate_free_space(directory)
  result = {name: directory[:name], alarm_if_less_than: directory[:alarm_if_less_than], path: directory[:path]}

  begin
    used_space = get_used_space(directory[:path])

    if (used_space > directory[:alarm_if_less_than])
      result[:error_message] = "The used space configured [#{directory[:alarm_if_less_than]}] for the directory #{directory[:path]} is at [#{used_space}]"
      result[:status] = 'error'
    else
      result[:status] = 'ok'
    end
  rescue Exception => ex
    result[:error_message] = ex.message
    result[:status] = 'error'
  end

  OpenStruct.new(result)
end