redis-health 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +42 -0
- data/lib/redis_health.rb +80 -0
- metadata +70 -0
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
### Redis Health is a simple monitoring tool for Redis that notifies when abnormal things are happening in Redis.
|
2
|
+
|
3
|
+
Install:
|
4
|
+
gem install 'redis-health'
|
5
|
+
|
6
|
+
Use:
|
7
|
+
require 'redis'
|
8
|
+
require 'redis-health'
|
9
|
+
require 'pony'
|
10
|
+
|
11
|
+
RedisHealth.configure do
|
12
|
+
watch('worker count fell below 2 for more then 1 minute') do
|
13
|
+
v = redis.scard('resque:party:workers')
|
14
|
+
{triggered: v < 2, value: v}
|
15
|
+
end
|
16
|
+
|
17
|
+
watch('redis connected client count fell below 3 for more then 30 seconds', 30) do
|
18
|
+
client_count = redis.info['connected_clients'].to_i
|
19
|
+
{triggered: client_count < 3, value: client_count}
|
20
|
+
end
|
21
|
+
|
22
|
+
watch('HOLY **** TEH FAIL LOGZ IZ HUGE', 1) do
|
23
|
+
v = redis.llen('resque:party:failed')
|
24
|
+
{triggered: v > 1000, value: v}
|
25
|
+
end
|
26
|
+
|
27
|
+
notify do |notices|
|
28
|
+
#TEXT EMAIL FAX POSTCARD TWEET GOES HERE
|
29
|
+
Pony.mail(:to => 'steve@hypermegaglobacorp.web', :from => 'failbot@hypermegaglobacorp.web', :html_body => '<h1>Some stuff seems to have failed, take a look pretty please</h1> ' + notices.join(', '))
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
redis = Redis.new
|
34
|
+
|
35
|
+
#runs watches and sleeps for 1 second in a loop
|
36
|
+
RedisHealth.new(redis).run
|
37
|
+
|
38
|
+
It calls your notifier block if a watch has been triggered for the specified number of seconds, passing it a list of triggered messages such as:
|
39
|
+
['HOLY **** TEH FAIL LOGZ IZ HUGE, value is now 100000', 'worker count fell below 2 for more then 1 minute, value is now 0']
|
40
|
+
|
41
|
+
And calls it again if a watch ceases to trigger, with a list of triggered messages such as:
|
42
|
+
['HOLY **** TEH FAIL LOGZ IZ HUGE no longer in effect, value is 10', 'worker count fell below 2 for more then 1 minute no longer in effect, value is now 100000']
|
data/lib/redis_health.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
class RedisHealth
|
2
|
+
VERSION = '0.0.1'
|
3
|
+
attr_accessor :redis, :triggered_times
|
4
|
+
@watchers = {}
|
5
|
+
|
6
|
+
class << self
|
7
|
+
attr_accessor :watchers, :notifier
|
8
|
+
|
9
|
+
def configure(&blk)
|
10
|
+
instance_eval(&blk)
|
11
|
+
end
|
12
|
+
|
13
|
+
def watch(label, time = 60, &blk)
|
14
|
+
w = {
|
15
|
+
:time => time,
|
16
|
+
:matcher => blk
|
17
|
+
}
|
18
|
+
watchers[label] = w
|
19
|
+
[label, w]
|
20
|
+
end
|
21
|
+
|
22
|
+
def notify(&blk)
|
23
|
+
@notifier = blk
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize(redis)
|
28
|
+
@redis = redis
|
29
|
+
@triggered_times = {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute_watches
|
33
|
+
self.class.watchers.collect do |watcher_array|
|
34
|
+
label, watcher_hash = watcher_array
|
35
|
+
triggered_times[label] ||= 0
|
36
|
+
|
37
|
+
matcher_result = self.instance_eval(&watcher_hash[:matcher])#.call(@redis)
|
38
|
+
triggered = matcher_result[:triggered]
|
39
|
+
value = matcher_result[:value]
|
40
|
+
notice = append_label_value(label, value, triggered)
|
41
|
+
times_was = triggered_times[label]
|
42
|
+
|
43
|
+
if triggered
|
44
|
+
triggered_times[label] += 1
|
45
|
+
if times_was == watcher_hash[:time]
|
46
|
+
notice
|
47
|
+
end
|
48
|
+
else
|
49
|
+
triggered_times[label] = 0
|
50
|
+
if times_was > 0 && times_was >= watcher_hash[:time]
|
51
|
+
notice
|
52
|
+
else
|
53
|
+
nil
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end.compact
|
57
|
+
end
|
58
|
+
|
59
|
+
def notify
|
60
|
+
notices = execute_watches
|
61
|
+
self.class.notifier.call(notices) unless notices.empty?
|
62
|
+
end
|
63
|
+
|
64
|
+
def run
|
65
|
+
loop do
|
66
|
+
notify
|
67
|
+
sleep 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def append_label_value(label, v, triggered)
|
74
|
+
notice = label
|
75
|
+
notice += ' is no longer in effect' unless triggered
|
76
|
+
notice += ", value is now #{v}" if v
|
77
|
+
notice
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis-health
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Max Justus Spransy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: &70131276238940 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70131276238940
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70131276238200 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.6.0
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70131276238200
|
36
|
+
description: When shit hits the fan in your redis db, Redis Health lets you know before
|
37
|
+
your customers do
|
38
|
+
email: maxjustus@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/redis_health.rb
|
44
|
+
- README.md
|
45
|
+
homepage: http://github.com/maxjustus/Redis-Health
|
46
|
+
licenses:
|
47
|
+
- MIT
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.11
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Knowing is half the battle
|
70
|
+
test_files: []
|