rails_health_checks 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 726057067f5f90f64123fe8aa2772bd94149b111f9bda7b51914fed99233f219
4
- data.tar.gz: a7baa24da9b0a1b04aa446612a73b062fe3e4ef20ff9b1e8efe7c10e74cab065
3
+ metadata.gz: d0f595984abf8a7db84183766d61918bdf684642b6ea67b2075afbda8f4cbae6
4
+ data.tar.gz: ab35a0deb32d298eae8dadc04c39dbf8ca34b8e77018625ebad8ba81e1901f34
5
5
  SHA512:
6
- metadata.gz: deb2906855bafc33635d8aeb3432fcced690f41cee05e8f3d7b288eec4908de97458291610dbb4b3c554e03b36ec85519e656fb38d67410517c0d6f056b0e81b
7
- data.tar.gz: f0e14a473c6f6ad646733a170f0c83232393a776a0e4b5dee124330b428e9402ed780644d97fb800611405636b7c9306599fd7b3ebcc17e8c0a6a86eec23c5aa
6
+ metadata.gz: 2f2db831794c15dbf59c6763ed65a092e9bc56db1dc87e35d4565cccd63303cfe9555a7b36f738e6a861086c0362f8eb98459e99ea46f5838bfeb3862130ebf5
7
+ data.tar.gz: 3d5b057c32506961cf0416d37ea45c70f5218767961ddeed208b37887abd7781187fc1f480aff2e5fb522bfad8400e355fa745a04ec876a064e1aeb938e91c78
data/README.md CHANGED
@@ -131,6 +131,9 @@ The block receives the `ActionDispatch::Request` object and must return a truthy
131
131
  | `:solid_queue` | Solid Queue DB connectivity; optional `config.solid_queue_job_count` threshold for pending jobs |
132
132
  | `:good_job` | GoodJob queue latency; optional `config.good_job_latency` (seconds) threshold for oldest pending job |
133
133
  | `:resque` | Resque Redis connectivity; optional `config.resque_queue_size` threshold for total queue depth |
134
+ | `:disk` | Free disk bytes via `df`; optional `config.disk_warn_threshold` / `config.disk_critical_threshold` (bytes) and `config.disk_path` (default: `/`) |
135
+ | `:memory` | Process RSS via `ps`; optional `config.memory_threshold` (bytes) reports `degraded` when exceeded |
136
+ | `:http` | HTTP GET to `config.http_url`; reports `critical` if response code differs from `config.http_expected_status` (default: `200`) or a network error occurs |
134
137
 
135
138
  [↑ Back to top](#table-of-contents)
136
139
 
@@ -10,7 +10,17 @@ module RailsHealthChecks
10
10
  sidekiq: -> { Checks::SidekiqCheck.new(queue_size: RailsHealthChecks.configuration.sidekiq_queue_size) },
11
11
  solid_queue: -> { Checks::SolidQueueCheck.new(job_count: RailsHealthChecks.configuration.solid_queue_job_count) },
12
12
  good_job: -> { Checks::GoodJobCheck.new(latency: RailsHealthChecks.configuration.good_job_latency) },
13
- resque: -> { Checks::ResqueCheck.new(queue_size: RailsHealthChecks.configuration.resque_queue_size) }
13
+ resque: -> { Checks::ResqueCheck.new(queue_size: RailsHealthChecks.configuration.resque_queue_size) },
14
+ memory: -> { Checks::MemoryCheck.new(threshold: RailsHealthChecks.configuration.memory_threshold) },
15
+ http: -> { Checks::HttpCheck.new(
16
+ url: RailsHealthChecks.configuration.http_url,
17
+ expected_status: RailsHealthChecks.configuration.http_expected_status
18
+ ) },
19
+ disk: -> { Checks::DiskCheck.new(
20
+ warn_threshold: RailsHealthChecks.configuration.disk_warn_threshold,
21
+ critical_threshold: RailsHealthChecks.configuration.disk_critical_threshold,
22
+ path: RailsHealthChecks.configuration.disk_path
23
+ ) }
14
24
  }.freeze
15
25
 
16
26
  def self.build(check_names)
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ module RailsHealthChecks
6
+ module Checks
7
+ class DiskCheck < Check
8
+ def initialize(warn_threshold: nil, critical_threshold: nil, path: "/")
9
+ @warn_threshold = warn_threshold
10
+ @critical_threshold = critical_threshold
11
+ @path = path
12
+ end
13
+
14
+ def call
15
+ free = nil
16
+ measure { free = free_bytes }
17
+
18
+ if @critical_threshold && free < @critical_threshold
19
+ return fail_with("free disk space #{free} bytes below critical threshold #{@critical_threshold} bytes")
20
+ end
21
+
22
+ if @warn_threshold && free < @warn_threshold
23
+ return warn_with("free disk space #{free} bytes below warn threshold #{@warn_threshold} bytes")
24
+ end
25
+
26
+ pass
27
+ rescue StandardError => e
28
+ fail_with(e.message)
29
+ end
30
+
31
+ private
32
+
33
+ def free_bytes
34
+ out, _, status = Open3.capture3("df", "-Pk", @path.to_s)
35
+ raise "df command failed with exit status #{status.exitstatus}" unless status.success?
36
+
37
+ parts = out.split("\n").last.split
38
+ parts[3].to_i * 1024
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "net/http"
4
+ require "uri"
5
+
6
+ module RailsHealthChecks
7
+ module Checks
8
+ class HttpCheck < Check
9
+ def initialize(url:, expected_status: 200)
10
+ @url = url
11
+ @expected_status = expected_status
12
+ end
13
+
14
+ def call
15
+ measure do
16
+ response = Net::HTTP.get_response(URI.parse(@url))
17
+ code = response.code.to_i
18
+ return fail_with("HTTP GET #{@url} returned #{code}, expected #{@expected_status}") if code != @expected_status
19
+ end
20
+ pass
21
+ rescue StandardError => e
22
+ fail_with(e.message)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "open3"
4
+
5
+ module RailsHealthChecks
6
+ module Checks
7
+ class MemoryCheck < Check
8
+ def initialize(threshold: nil)
9
+ @threshold = threshold
10
+ end
11
+
12
+ def call
13
+ rss = nil
14
+ measure { rss = rss_bytes }
15
+
16
+ if @threshold && rss > @threshold
17
+ return warn_with("process RSS #{rss} bytes exceeds threshold #{@threshold} bytes")
18
+ end
19
+
20
+ pass
21
+ rescue StandardError => e
22
+ fail_with(e.message)
23
+ end
24
+
25
+ private
26
+
27
+ def rss_bytes
28
+ out, _, status = Open3.capture3("ps", "-o", "rss=", "-p", Process.pid.to_s)
29
+ raise "ps command failed with exit status #{status.exitstatus}" unless status.success?
30
+
31
+ out.strip.to_i * 1024
32
+ end
33
+ end
34
+ end
35
+ end
@@ -3,7 +3,8 @@
3
3
  module RailsHealthChecks
4
4
  class Configuration
5
5
  attr_accessor :checks, :timeout, :allowed_ips, :token, :sidekiq_queue_size, :solid_queue_job_count, :good_job_latency,
6
- :resque_queue_size
6
+ :resque_queue_size, :disk_warn_threshold, :disk_critical_threshold, :disk_path,
7
+ :memory_threshold, :http_url, :http_expected_status
7
8
  attr_reader :authenticate_block
8
9
 
9
10
  def initialize
@@ -16,6 +17,12 @@ module RailsHealthChecks
16
17
  @solid_queue_job_count = nil
17
18
  @good_job_latency = nil
18
19
  @resque_queue_size = nil
20
+ @disk_warn_threshold = nil
21
+ @disk_critical_threshold = nil
22
+ @disk_path = "/"
23
+ @memory_threshold = nil
24
+ @http_url = nil
25
+ @http_expected_status = 200
19
26
  end
20
27
 
21
28
  def authenticate(&block)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsHealthChecks
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
@@ -11,6 +11,9 @@ require "rails_health_checks/checks/sidekiq_check"
11
11
  require "rails_health_checks/checks/solid_queue_check"
12
12
  require "rails_health_checks/checks/good_job_check"
13
13
  require "rails_health_checks/checks/resque_check"
14
+ require "rails_health_checks/checks/disk_check"
15
+ require "rails_health_checks/checks/memory_check"
16
+ require "rails_health_checks/checks/http_check"
14
17
  require "rails_health_checks/check_registry"
15
18
  require "rails_health_checks/response_builder"
16
19
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_health_checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck Smith
@@ -46,7 +46,10 @@ files:
46
46
  - lib/rails_health_checks/check_registry.rb
47
47
  - lib/rails_health_checks/checks/cache_check.rb
48
48
  - lib/rails_health_checks/checks/database_check.rb
49
+ - lib/rails_health_checks/checks/disk_check.rb
49
50
  - lib/rails_health_checks/checks/good_job_check.rb
51
+ - lib/rails_health_checks/checks/http_check.rb
52
+ - lib/rails_health_checks/checks/memory_check.rb
50
53
  - lib/rails_health_checks/checks/resque_check.rb
51
54
  - lib/rails_health_checks/checks/sidekiq_check.rb
52
55
  - lib/rails_health_checks/checks/solid_queue_check.rb