Class: RailsHealthChecks::Checks::DiskCheck

Inherits:
RailsHealthChecks::Check show all
Defined in:
lib/rails_health_checks/checks/disk_check.rb

Instance Attribute Summary

Attributes inherited from RailsHealthChecks::Check

#latency_ms, #message, #status

Instance Method Summary collapse

Constructor Details

#initialize(warn_threshold: nil, critical_threshold: nil, path: "/") ⇒ DiskCheck

Returns a new instance of DiskCheck.



8
9
10
11
12
# File 'lib/rails_health_checks/checks/disk_check.rb', line 8

def initialize(warn_threshold: nil, critical_threshold: nil, path: "/")
  @warn_threshold = warn_threshold
  @critical_threshold = critical_threshold
  @path = path
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_health_checks/checks/disk_check.rb', line 14

def call
  free = nil
  measure { free = free_bytes }

  if @critical_threshold && free < @critical_threshold
    return fail_with("free disk space #{free} bytes below critical threshold #{@critical_threshold} bytes")
  end

  if @warn_threshold && free < @warn_threshold
    return warn_with("free disk space #{free} bytes below warn threshold #{@warn_threshold} bytes")
  end

  pass
rescue StandardError => e
  fail_with(e.message)
end