dead-man 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/dead_man/heartbeat.rb +10 -0
- data/lib/dead_man/switch.rb +62 -0
- data/lib/dead_man.rb +13 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 29843644af922f92a5d0e528bff03b2a017475f9
|
4
|
+
data.tar.gz: 75c26f7434eb4979c34622ce257a2b00b7d86b24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 321dca439854addec1c6c6f8b76bf6676a2fb5a8ee28da418d093eaefb680646e7f815d354ca24b36069dadaa1b92a97010fb2507535545a1c1b29e997e3e2de
|
7
|
+
data.tar.gz: d577057965640ee05127a57b41bc0a53c02a4f03d3fdae60f8ebe61a97aa830a0076a94c3159755df6fe379bce1e5fbc6ddbdd591d0d2cc2c5517b8c52bc2592
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module DeadMan
|
2
|
+
module Switch
|
3
|
+
INTERVAL_THRESHOLD = 0.2 # 20% padding
|
4
|
+
SWITCHES = {}
|
5
|
+
CALLBACKS = []
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def run
|
9
|
+
SWITCHES.each_key do |switch|
|
10
|
+
check(switch)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def register_callback(callback)
|
15
|
+
CALLBACKS << callback
|
16
|
+
end
|
17
|
+
|
18
|
+
def register_switch(name, interval)
|
19
|
+
SWITCHES[name] = interval
|
20
|
+
end
|
21
|
+
|
22
|
+
def check(switch)
|
23
|
+
if SWITCHES.has_key?(switch)
|
24
|
+
timestamp = last_heartbeat_at(switch)
|
25
|
+
raise 'Unrecorded switch' if timestamp.nil?
|
26
|
+
alert(switch, timestamp) if alertable?(timestamp, SWITCHES[switch])
|
27
|
+
else
|
28
|
+
return false
|
29
|
+
end
|
30
|
+
rescue
|
31
|
+
notify("Check failed for #{switch}. This is usually because an improper heartbeat timestamp was stored.")
|
32
|
+
end
|
33
|
+
|
34
|
+
def last_heartbeat_at(switch)
|
35
|
+
key = DeadMan.key(switch)
|
36
|
+
timestamp = DeadMan.redis.get(key)
|
37
|
+
Time.parse(timestamp)
|
38
|
+
rescue
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def alertable?(heartbeat_at, interval)
|
43
|
+
heartbeat_at < adjusted_interval(interval).ago
|
44
|
+
end
|
45
|
+
|
46
|
+
# Gives an INTERVAL_THRESHOLD padding on interval
|
47
|
+
# e.g. 60.seconds -> 72.seconds
|
48
|
+
def adjusted_interval(interval)
|
49
|
+
interval + interval * INTERVAL_THRESHOLD
|
50
|
+
end
|
51
|
+
|
52
|
+
def alert(switch, timestamp)
|
53
|
+
notify("#{switch} died. The switch was last triggered at #{timestamp}")
|
54
|
+
end
|
55
|
+
|
56
|
+
def notify(message)
|
57
|
+
CALLBACKS.each do |callback|
|
58
|
+
callback.call(message)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/dead_man.rb
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dead-man
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Coleman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: timecop
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Know when your systems are dead.
|
70
|
+
email: sean@seancoleman.net
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/dead_man.rb
|
76
|
+
- lib/dead_man/switch.rb
|
77
|
+
- lib/dead_man/heartbeat.rb
|
78
|
+
homepage: http://rubygems.org/gems/hola
|
79
|
+
licenses: []
|
80
|
+
metadata: {}
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.0.14
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: The dead man's switch
|
101
|
+
test_files: []
|