health-monitor-rails 7.4.0 → 7.5.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 +4 -4
- data/README.md +2 -0
- data/lib/health_monitor/providers/redis.rb +26 -6
- data/lib/health_monitor/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fd4554ce52f49c39225bc9bc7459350a0905b9f
|
4
|
+
data.tar.gz: a26af54d0d8fc422bc18bc298801850b7278a9b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
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
|
+
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-
|
11
|
+
date: 2017-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|