kingkong 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +9 -1
- data/Guardfile +5 -0
- data/README.md +28 -2
- data/Rakefile +4 -1
- data/lib/kingkong.rb +10 -0
- data/lib/kingkong/aggregator.rb +2 -2
- data/lib/kingkong/logging.rb +0 -5
- data/lib/kingkong/pinger.rb +53 -0
- data/lib/kingkong/version.rb +1 -1
- data/spec/lib/kingkong/pinger_spec.rb +19 -0
- data/spec/lib/kingkong_spec.rb +4 -0
- data/spec/spec_helper.rb +8 -0
- metadata +13 -6
- data/lib/README.md +0 -33
data/Gemfile
CHANGED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
| /.----/ O O \----.\ |
|
9
9
|
\/ | | \/
|
10
10
|
| |
|
11
|
-
| |
|
11
|
+
| | KingKong gets what KingKong wants!
|
12
12
|
| |
|
13
13
|
_\ -.,_____,.- /_
|
14
14
|
,.-" "-.,_________,.-" "-.,
|
@@ -26,8 +26,34 @@
|
|
26
26
|
/"-.,__,.-"\ /"-.,__,.-"\"-.,_,.-"\
|
27
27
|
| \ / | |
|
28
28
|
| | | |
|
29
|
-
\__|__|__|__/ \__|__|__|__/ \_|__|__/
|
29
|
+
\__|__|__|__/ \__|__|__|__/ \_|__|__/
|
30
30
|
|
31
31
|
KingKong makes it easy to build full-stack ping-pong checks. You might need this to check and graph out the response time on your website, Twitter application, SMS gateway, or whatever else you'd connect to a network.
|
32
32
|
|
33
|
+
When its done, it will look something like this:
|
34
|
+
|
35
|
+
KingKing.monitor {
|
36
|
+
socket '/tmp/kingkong.socket' # Munin can check this for stats
|
37
|
+
|
38
|
+
ping(:google).every(3).seconds do |ping|
|
39
|
+
google = http('http://www.google.com/').get
|
40
|
+
|
41
|
+
ping.on_timeout {
|
42
|
+
# ZOMG! Email the admin! Google is down!
|
43
|
+
}
|
44
|
+
|
45
|
+
ping.start_time # Start the clock!
|
46
|
+
google.callback { # This triggers the request
|
47
|
+
ping.end_time # And this stops the clock!
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
ping(:twitter).every(10).seconds do |ping|
|
52
|
+
# Wire up your own thing in here that tweets
|
53
|
+
# .. and when you pick that up, end the pong!
|
54
|
+
end
|
55
|
+
}
|
56
|
+
|
57
|
+
and its going to aggregate stats so you can plug it into munin and get all sorts of graphing goodness.
|
58
|
+
|
33
59
|
Stay tuned, I'm still working out the ping DSL and reporting infrastructure!
|
data/Rakefile
CHANGED
data/lib/kingkong.rb
CHANGED
@@ -2,7 +2,17 @@ require "kingkong/version"
|
|
2
2
|
|
3
3
|
module KingKong
|
4
4
|
autoload :Ping, 'kingkong/ping'
|
5
|
+
autoload :Pinger, 'kingkong/pinger'
|
5
6
|
autoload :Server, 'kingkong/server'
|
6
7
|
autoload :Logging, 'kingkong/logging'
|
7
8
|
autoload :Aggregator, 'kingkong/aggregator'
|
9
|
+
|
10
|
+
# Default logger for KingKong.
|
11
|
+
def self.logger
|
12
|
+
@logger ||= Logger.new($stdout)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.logger=(logger)
|
16
|
+
@logger = logger
|
17
|
+
end
|
8
18
|
end
|
data/lib/kingkong/aggregator.rb
CHANGED
@@ -4,7 +4,7 @@ module KingKong
|
|
4
4
|
class Aggregator
|
5
5
|
attr_reader :sum, :max_count, :pings, :started_at
|
6
6
|
|
7
|
-
def initialize(max_count=
|
7
|
+
def initialize(max_count=10_000)
|
8
8
|
@max_count = max_count
|
9
9
|
reset
|
10
10
|
end
|
@@ -48,7 +48,7 @@ module KingKong
|
|
48
48
|
|
49
49
|
# Reset all of the counts to 0 and empty all of the pings
|
50
50
|
def reset
|
51
|
-
@sum = 0
|
51
|
+
@sum = 0.0
|
52
52
|
@pings = Array.new
|
53
53
|
@started_at = Time.now
|
54
54
|
end
|
data/lib/kingkong/logging.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'eventmachine'
|
2
|
+
|
3
|
+
module KingKong
|
4
|
+
class Pinger
|
5
|
+
include Logging
|
6
|
+
|
7
|
+
attr_accessor :aggregator, :duration
|
8
|
+
|
9
|
+
def initialize(duration=5)
|
10
|
+
@duration = duration
|
11
|
+
end
|
12
|
+
|
13
|
+
# Starts the pinger
|
14
|
+
def start(&block)
|
15
|
+
logger.debug "Starting pinger #{self}"
|
16
|
+
@timer = EventMachine::PeriodicTimer.new(duration){ ping(&block) }
|
17
|
+
ping(&block)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Stop the pinger from executing
|
21
|
+
def stop
|
22
|
+
logger.debug "Stopping pinger #{self}"
|
23
|
+
@timer.cancel if @timer
|
24
|
+
end
|
25
|
+
|
26
|
+
# Gather up all the numbers we need for reporting later on
|
27
|
+
def aggregator
|
28
|
+
@aggregatore ||= Aggregator.new
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
# Add all of the instrumentation callbacks into the ping so we can aggregate it later
|
33
|
+
def ping(&block)
|
34
|
+
ping = Ping::Deferrable.new(30, sequencer)
|
35
|
+
# Register the aggregator to process the ping
|
36
|
+
ping.callback {
|
37
|
+
logger.debug "Ping #{ping} successful"
|
38
|
+
aggregator.process ping
|
39
|
+
}
|
40
|
+
ping.errback {
|
41
|
+
logger.debug "Ping #{ping} error (probably a timeout)"
|
42
|
+
aggregator.process ping
|
43
|
+
}
|
44
|
+
# Now pass the ping into the block so we can start/stop it
|
45
|
+
yield ping if block_given?
|
46
|
+
end
|
47
|
+
|
48
|
+
# Setup a squencer that's unique specifically to this pinger
|
49
|
+
def sequencer
|
50
|
+
@sequencer ||= Ping::Sequencer.new
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/kingkong/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe KingKong::Pinger do
|
4
|
+
include EM::Ventually
|
5
|
+
|
6
|
+
before(:all) do
|
7
|
+
@pinger = KingKong::Pinger.new
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should start pinging" do
|
11
|
+
@pinger.start
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should stop pinging" do
|
15
|
+
@pinger.stop
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should sequence pings"
|
19
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kingkong
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-06 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
16
|
-
requirement: &
|
16
|
+
requirement: &70207424167020 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,7 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70207424167020
|
25
25
|
description: Have you ever wanted to shoot a message throught Twitter, have your app
|
26
26
|
pick it up, do some work on it, and report how long it takes? KingKong makes it
|
27
27
|
slightly easier to do this with a DSL for writing custom pings and by providing
|
@@ -37,19 +37,23 @@ files:
|
|
37
37
|
- .gitignore
|
38
38
|
- .rvmrc
|
39
39
|
- Gemfile
|
40
|
+
- Guardfile
|
40
41
|
- README.md
|
41
42
|
- Rakefile
|
42
43
|
- bin/kingkong-munin
|
43
44
|
- bin/kingkong-server
|
44
45
|
- kingkong.gemspec
|
45
|
-
- lib/README.md
|
46
46
|
- lib/kingkong.rb
|
47
47
|
- lib/kingkong/aggregator.rb
|
48
48
|
- lib/kingkong/cli.rb
|
49
49
|
- lib/kingkong/logging.rb
|
50
50
|
- lib/kingkong/ping.rb
|
51
|
+
- lib/kingkong/pinger.rb
|
51
52
|
- lib/kingkong/server.rb
|
52
53
|
- lib/kingkong/version.rb
|
54
|
+
- spec/lib/kingkong/pinger_spec.rb
|
55
|
+
- spec/lib/kingkong_spec.rb
|
56
|
+
- spec/spec_helper.rb
|
53
57
|
homepage: ''
|
54
58
|
licenses: []
|
55
59
|
post_install_message:
|
@@ -74,4 +78,7 @@ rubygems_version: 1.8.6
|
|
74
78
|
signing_key:
|
75
79
|
specification_version: 3
|
76
80
|
summary: Build complex network application health checks with Ruby and EventMachine
|
77
|
-
test_files:
|
81
|
+
test_files:
|
82
|
+
- spec/lib/kingkong/pinger_spec.rb
|
83
|
+
- spec/lib/kingkong_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
data/lib/README.md
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
# KingKong
|
2
|
-
|
3
|
-
,.-" "-.,
|
4
|
-
/ === \
|
5
|
-
/ ======= \
|
6
|
-
__| (o) (0) |__
|
7
|
-
/ _| .---. |_ \
|
8
|
-
| /.----/ O O \----.\ |
|
9
|
-
\/ | | \/
|
10
|
-
| |
|
11
|
-
| | KingKong gets what KingKong wants!
|
12
|
-
| |
|
13
|
-
_\ -.,_____,.- /_
|
14
|
-
,.-" "-.,_________,.-" "-.,
|
15
|
-
/ | | \
|
16
|
-
| l. .l |
|
17
|
-
| | | |
|
18
|
-
l. | | .l
|
19
|
-
| l. .l | \,
|
20
|
-
l. | | .l \,
|
21
|
-
| | | | \,
|
22
|
-
l. | | .l |
|
23
|
-
| | | | |
|
24
|
-
| |---| | |
|
25
|
-
| | | | |
|
26
|
-
/"-.,__,.-"\ /"-.,__,.-"\"-.,_,.-"\
|
27
|
-
| \ / | |
|
28
|
-
| | | |
|
29
|
-
\__|__|__|__/ \__|__|__|__/ \_|__|__/
|
30
|
-
|
31
|
-
KingKong makes it easy to build full-stack ping-pong checks. You might need this to check and graph out the response time on your website, Twitter application, SMS gateway, or whatever else you'd connect to a network.
|
32
|
-
|
33
|
-
Stay tuned, I'm still working out the ping DSL and reporting infrastructure!
|