health-monitor-rails 12.7.0 → 12.9.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: 65ddef8cba3d98c9824273f2eb677bb4eb5797a88ea3a020d846ab9e7b170bf9
4
- data.tar.gz: 30b1ff30cdc3c8c95a180701b251756514cacc4f8a6969c07dc07b21fddb538c
3
+ metadata.gz: 99640f8600704695ca8c0a21fa562a6fe86e5cad4f498b5e4097c221b7bbb7c6
4
+ data.tar.gz: c58781a881a9d64488492bb418ff6215689871fa34010fa7d0da53c31b0e9d1b
5
5
  SHA512:
6
- metadata.gz: bdba690258230630638d475e00cad004127a086cf548460504864038ec1e02eeb434e083cf49e7c23ab00f08ef764e7bacee01a1beaec16d01c1486854ee6a76
7
- data.tar.gz: ca61f98fca9a3adc8b89c47748d82ce7a9523842b807d757171474e73f13721d2db6085f65813b3be2829b7f1b3ff3a176020727eae4d11f5392e5e2b4b1314d
6
+ metadata.gz: ddd214cbfc05952f72e73f4c9727c1f136100b771752e1cf96b538ea35cc7ef5cefba154b685edec23622c5298c29c8e91643da3482e68ca50740ef9326afdfd
7
+ data.tar.gz: 183bf0cf7a64604e153c8e822aa9f6c1964c07e942c57b62e6dc1bcfbb27505244b46a27b66a9cdd88dc4f1ca746e6b2cd69e83ab43ccf4a89fd93c1ebe4e487
data/README.md CHANGED
@@ -415,6 +415,15 @@ end
415
415
 
416
416
  This will make the page to be served in the `/status` endpoint for instance (from where the engine was mounted).
417
417
 
418
+ ### Showing Response Times of Checks
419
+
420
+ ```ruby
421
+ HealthMonitor.configure do |config|
422
+ config.response_threshold = 0.8
423
+ end
424
+ ```
425
+ By default, this setting is disabled. Enable it and enter a floating‑point threshold value. Once enabled, each provider logs its response time; if a provider’s response time exceeds the threshold, the issue will be visible via the `/check` endpoint.
426
+
418
427
  ### Monitoring Script
419
428
 
420
429
  A Nagios/Shinken/Icinga/Icinga2 plugin is available in `extra` directory.
@@ -116,6 +116,17 @@
116
116
  color: rgb(71 85 105);
117
117
  }
118
118
 
119
+ .response {
120
+ font-weight: 800;
121
+ }
122
+
123
+ .bordering {
124
+ border: solid 1px red;
125
+ width: auto;
126
+ margin: 0.5em;
127
+ padding: 0.5em;
128
+ }
129
+
119
130
  dt {
120
131
  min-width: 10vw;
121
132
  font-size: 0.875rem;
@@ -148,7 +159,7 @@
148
159
  <div class="border">
149
160
  <dl>
150
161
  <% @statuses[:results].each_with_index do |status, index| %>
151
- <div class="<%= index.odd? ? 'bg-gray' : 'bg-white' %> item">
162
+ <div class="<%= index.odd? ? 'bg-gray' : 'bg-white' %> <%= 'bordering' if status[:slow_response] %> item">
152
163
  <dt class="name">
153
164
  <%= status[:name] %>
154
165
  </dt>
@@ -157,6 +168,11 @@
157
168
  <div class="state <%= 'red' if status[:status].downcase == 'error' %> font-bold">
158
169
  <%= status[:status] %>
159
170
  </div>
171
+ <% if HealthMonitor.configuration.response_threshold %>
172
+ <div class="response <%= 'red' if status[:slow_response] %> font-bold">
173
+ <%= status[:response_time] %>
174
+ </div>
175
+ <% end %>
160
176
  <% if !status[:message].empty? %>
161
177
  <div class="message"><%= status[:message] %></div>
162
178
  <% end %>
@@ -8,7 +8,8 @@ module HealthMonitor
8
8
  :environment_variables,
9
9
  :error_callback,
10
10
  :hide_footer,
11
- :path
11
+ :path,
12
+ :response_threshold
12
13
  attr_reader :providers
13
14
 
14
15
  def initialize
@@ -33,18 +33,25 @@ module HealthMonitor
33
33
  }
34
34
  end
35
35
 
36
+ def measure_response_time(&block)
37
+ start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
38
+ block.call
39
+ (Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time).round(3)
40
+ end
41
+
36
42
  private
37
43
 
38
44
  def provider_result(provider, request)
39
45
  monitor = provider
40
46
  monitor.request = request
41
- monitor.check!
42
47
 
43
- {
44
- name: provider.name,
45
- message: '',
46
- status: STATUSES[:ok]
47
- }
48
+ if HealthMonitor.configuration.response_threshold
49
+ response_time = measure_response_time { monitor.check! }
50
+ else
51
+ monitor.check!
52
+ end
53
+
54
+ result_data(provider, response_time)
48
55
  rescue StandardError => e
49
56
  configuration.error_callback.try(:call, e)
50
57
 
@@ -54,6 +61,19 @@ module HealthMonitor
54
61
  status: provider.critical ? STATUSES[:error] : STATUSES[:warning]
55
62
  }
56
63
  end
64
+
65
+ def result_data(provider, response_time)
66
+ {
67
+ name: provider.name,
68
+ message: '',
69
+ status: STATUSES[:ok]
70
+ }.tap do |result|
71
+ if response_time
72
+ result[:response_time] = response_time
73
+ result[:slow_response] = true if HealthMonitor.configuration.response_threshold < response_time
74
+ end
75
+ end
76
+ end
57
77
  end
58
78
 
59
79
  HealthMonitor.configure
@@ -7,10 +7,12 @@ module HealthMonitor
7
7
  class CacheException < StandardError; end
8
8
 
9
9
  class Cache < Base
10
+ EXPIRED_TIME_SECONDS = 3
11
+
10
12
  def check!
11
13
  time = Time.now.to_formatted_s(:rfc2822)
12
14
 
13
- Rails.cache.write(key, time)
15
+ Rails.cache.write(key, time, expires_in: EXPIRED_TIME_SECONDS)
14
16
  fetched = Rails.cache.read(key)
15
17
 
16
18
  raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time
@@ -9,6 +9,8 @@ module HealthMonitor
9
9
  class RedisException < StandardError; end
10
10
 
11
11
  class Redis < Base
12
+ EXPIRED_TIME_SECONDS = 3
13
+
12
14
  class Configuration < Base::Configuration
13
15
  DEFAULT_URL = nil
14
16
 
@@ -45,7 +47,7 @@ module HealthMonitor
45
47
  def check_values!
46
48
  time = Time.now.to_formatted_s(:rfc2822)
47
49
 
48
- redis.with { |conn| conn.set(key, time) }
50
+ redis.with { |conn| conn.set(key, time, ex: EXPIRED_TIME_SECONDS) }
49
51
  fetched = redis.with { |conn| conn.get(key) }
50
52
 
51
53
  raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '12.7.0'
4
+ VERSION = '12.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: health-monitor-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 12.7.0
4
+ version: 12.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leonid Beder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-04-09 00:00:00.000000000 Z
11
+ date: 2025-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties