health-monitor-rails 7.4.0 → 7.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85424832894f22b0c7ea378d9f196b5391b75309
4
- data.tar.gz: 4a94ec537d24ec741d9aff84123541abd8a9995a
3
+ metadata.gz: 2fd4554ce52f49c39225bc9bc7459350a0905b9f
4
+ data.tar.gz: a26af54d0d8fc422bc18bc298801850b7278a9b4
5
5
  SHA512:
6
- metadata.gz: 42aae7d82352be072f1aaa67465cb83bb2643fc372b79d3ebb7699aefe9638b191c9becf834c0e0f138f8a0d64a281e3edb410d8d8dc56aad972a4e9b772a866
7
- data.tar.gz: 8895295d39d649d1c53a7a1256d72d7fe4f797ca25d3e323a2b6819cc5c68138b93d381323c2ddbb1000554198fa25b7e681ec86452d4bfaf9b41342517eb065
6
+ metadata.gz: 047ba4b0686191d9514179c32534b17924b6ca6b652e51a7adf882c7d784b5bf74655c0db8bb4623dc2de4fe7fd7fe17a0a721f60a272be3c4fa57fbbb0c77f6
7
+ data.tar.gz: 9be9324ea5ded4360e663d5fa4238b3fb774731503864f13cf8b46f49b5397037d6f0e02f5363de11ea82e2d0ee539b876be87942a7c59577bd2b69f9d25a3d5
data/README.md CHANGED
@@ -163,6 +163,7 @@ HealthMonitor.configure do |config|
163
163
  config.redis.configure do |redis_config|
164
164
  redis_config.connection = Redis.current # use your custom redis connection
165
165
  redis_config.url = 'redis://user:pass@example.redis.com:90210/' # or URL
166
+ redis_config.max_used_memory = 200 # Megabytes
166
167
  end
167
168
  end
168
169
  ```
@@ -178,6 +179,7 @@ The currently supported settings are:
178
179
 
179
180
  * `url`: the url used to connect to your Redis instance - note, this is an optional configuration and will use the default connection if not specified
180
181
  * `connection`: Use custom redis connection (e.g., `Redis.current`).
182
+ * `max_used_memory`: Set maximum expected memory usage of Redis in megabytes. Prevent memory leaks and keys overstore.
181
183
 
182
184
  ### Adding a Custom Provider
183
185
  It's also possible to add custom health check providers suited for your needs (of course, it's highly appreciated and encouraged if you'd contribute useful providers to the project).
@@ -8,7 +8,7 @@ module HealthMonitor
8
8
  class Configuration
9
9
  DEFAULT_URL = nil
10
10
 
11
- attr_accessor :url, :connection
11
+ attr_accessor :url, :connection, :max_used_memory
12
12
 
13
13
  def initialize
14
14
  @url = DEFAULT_URL
@@ -24,19 +24,31 @@ module HealthMonitor
24
24
  end
25
25
 
26
26
  def check!
27
+ check_values!
28
+ check_max_used_memory!
29
+ rescue Exception => e
30
+ raise RedisException.new(e.message)
31
+ ensure
32
+ redis.close
33
+ end
34
+
35
+ private
36
+
37
+ def check_values!
27
38
  time = Time.now.to_s(:rfc2822)
28
39
 
29
40
  redis.set(key, time)
30
41
  fetched = redis.get(key)
31
42
 
32
43
  raise "different values (now: #{time}, fetched: #{fetched})" if fetched != time
33
- rescue Exception => e
34
- raise RedisException.new(e.message)
35
- ensure
36
- redis.close
37
44
  end
38
45
 
39
- private
46
+ def check_max_used_memory!
47
+ return unless configuration.max_used_memory
48
+ return if used_memory_mb <= configuration.max_used_memory
49
+
50
+ raise "#{used_memory_mb}Mb memory using is higher than #{configuration.max_used_memory}Mb maximum expected"
51
+ end
40
52
 
41
53
  def key
42
54
  @key ||= ['health', request.try(:remote_ip)].join(':')
@@ -52,6 +64,14 @@ module HealthMonitor
52
64
  ::Redis.new
53
65
  end
54
66
  end
67
+
68
+ def bytes_to_megabytes(bytes)
69
+ (bytes.to_f / 1024 / 1024 * 100).round
70
+ end
71
+
72
+ def used_memory_mb
73
+ bytes_to_megabytes(redis.info['used_memory'])
74
+ end
55
75
  end
56
76
  end
57
77
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HealthMonitor
4
- VERSION = '7.4.0'.freeze
4
+ VERSION = '7.5.0'.freeze
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: 7.4.0
4
+ version: 7.5.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: 2017-12-27 00:00:00.000000000 Z
11
+ date: 2017-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails