kingkong 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .DS_Store
2
+ *.gem
3
+ .bundle
4
+ Gemfile.lock
5
+ pkg/*
6
+ bin/polleverywhere
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use --create --install 1.9.2@kingkong
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in kingkong.gemspec
4
+ gemspec
5
+
6
+ gem 'em-http-request'
7
+ gem 'json'
data/README.md ADDED
@@ -0,0 +1,33 @@
1
+ # KingKong
2
+
3
+ ,.-" "-.,
4
+ / === \
5
+ / ======= \
6
+ __| (o) (0) |__
7
+ / _| .---. |_ \
8
+ | /.----/ O O \----.\ |
9
+ \/ | | \/
10
+ | |
11
+ | |
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
+ \__|__|__|__/ \__|__|__|__/ \_|__|__/ KingKong gets what KingKong wants!
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!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'socket'
4
+ require 'yaml'
5
+
6
+ puts case ARGV.first
7
+ when /config/
8
+ %(graph_title Result latency
9
+ graph_category App
10
+ graph_vlabel load
11
+ load.label load)
12
+ else
13
+ stats = YAML.load UNIXSocket.new("/tmp/kingkong.socket").gets("\r\n")
14
+ %(load.value #{stats[:avg]})
15
+ end
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'kingkong'
6
+
7
+ EventMachine::run do
8
+ trap('TERM') { EM.stop }
9
+ trap('INT') { EM.stop }
10
+ end
data/kingkong.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "kingkong/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "kingkong"
7
+ s.version = KingKong::VERSION
8
+ s.authors = ["Brad Gessler"]
9
+ s.email = ["brad@bradgessler.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Build complex network application health checks with Ruby and EventMachine}
12
+ s.description = %q{Have you ever wanted to shoot a message throught Twitter, have your app pick it up, do some work on it, and report how long it takes? KingKong makes it slightly easier to do this with a DSL for writing custom pings and by providing basic reporting facilities that plug into graphing applications like Munin.}
13
+
14
+ s.rubyforge_project = "kingkong"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ s.add_runtime_dependency "eventmachine"
24
+ end
data/lib/README.md ADDED
@@ -0,0 +1,33 @@
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!
data/lib/kingkong.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "kingkong/version"
2
+
3
+ module KingKong
4
+ autoload :Ping, 'kingkong/ping'
5
+ autoload :Server, 'kingkong/server'
6
+ autoload :Logging, 'kingkong/logging'
7
+ autoload :Aggregator, 'kingkong/aggregator'
8
+ end
@@ -0,0 +1,56 @@
1
+ module KingKong
2
+ # Processes and aggregates pings for reporting. These stats will probably
3
+ # be accessed throug the KingKong::Server UNIX socket.
4
+ class Aggregator
5
+ attr_reader :sum, :max_count, :pings, :started_at
6
+
7
+ def initialize(max_count=10)
8
+ @max_count = max_count
9
+ reset
10
+ end
11
+
12
+ # Accept a ping message, keep a running total, and make sure we stay within the
13
+ # size of the number of samples that we want to keep around.
14
+ def process(ping)
15
+ @sum+=ping.latency
16
+ pings.push ping
17
+
18
+ # Take out the old ping if we're approaching our max sample size and substruct it
19
+ # from the running latency sum
20
+ if count > max_count and ping = pings.shift
21
+ @sum-=ping.latency
22
+ end
23
+ end
24
+
25
+ # Average latency of pings
26
+ def avg
27
+ count.zero? ? 0 : sum / count
28
+ end
29
+
30
+ # Number of pings
31
+ def count
32
+ pings.size
33
+ end
34
+
35
+ # Basic statistical summary of ping latency
36
+ def to_hash
37
+ {
38
+ :avg => avg,
39
+ :count => count,
40
+ :sum => sum,
41
+ :started_at => started_at
42
+ }
43
+ end
44
+
45
+ def to_s
46
+ to_hash.to_yaml
47
+ end
48
+
49
+ # Reset all of the counts to 0 and empty all of the pings
50
+ def reset
51
+ @sum = 0
52
+ @pings = Array.new
53
+ @started_at = Time.now
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,4 @@
1
+ module KingKong
2
+ class CLI < Thor
3
+ end
4
+ end
@@ -0,0 +1,15 @@
1
+ require 'logger'
2
+
3
+ module KingKong
4
+ # Logging concern for each class
5
+ module Logging
6
+ def logger
7
+ KingKong.logger
8
+ end
9
+ end
10
+
11
+ # Default logger for KingKong.
12
+ def self.logger
13
+ @logger ||= Logger.new($stdout)
14
+ end
15
+ end
@@ -0,0 +1,102 @@
1
+ require 'eventmachine'
2
+
3
+ module KingKong
4
+ # Encaspulates and calculates latency.
5
+ class Ping
6
+ attr_accessor :end_time, :ttl
7
+
8
+ def initialize(ttl=30,sequencer=self.class.sequencer)
9
+ # Time out is when the ping should give up!
10
+ @ttl, @sequencer = ttl, sequencer
11
+ end
12
+
13
+ # Lazily grab a id
14
+ def id
15
+ @id ||= @sequencer.next
16
+ end
17
+
18
+ # When did the ping start? This is also what starts the time for this thing
19
+ def start_time
20
+ unless @start_time
21
+ @start_time = current_time
22
+ end
23
+ @start_time
24
+ end
25
+
26
+ # Set the end time
27
+ def pong
28
+ @end_time ||= current_time
29
+ end
30
+
31
+ # How long did it take to clear the message?
32
+ def latency
33
+ end_time - start_time if end_time
34
+ end
35
+
36
+ # Did this get ponged yet?
37
+ def completed?
38
+ !!end_time
39
+ end
40
+
41
+ # Is this ping still on its journy? Will it make it back! It hasn't yet...
42
+ def active?
43
+ !timed_out? or !completed?
44
+ end
45
+
46
+ # Did we not receive a pong?
47
+ def timed_out?
48
+ start_time + ttl < current_time and not end_time
49
+ end
50
+
51
+ # Give us the current time in seconds
52
+ def current_time
53
+ Time.now.to_f
54
+ end
55
+
56
+ # Generates ids for pings
57
+ def self.sequencer
58
+ @sequencer ||= Sequencer.new
59
+ end
60
+ end
61
+
62
+ # Keeps track of the results heading in/out. We could just use
63
+ # some totally random GUID instead of bothering with this, but
64
+ # having a 1,2,3... sequence makes it much easier to spot check
65
+ # tests to verify whether or not messages are being sent correctly.
66
+ class Ping::Sequencer
67
+ attr_reader :count, :run
68
+
69
+ def initialize(run=Time.now.to_i)
70
+ @run, @count = run, 0
71
+ end
72
+
73
+ # Tick up the restul count and give us the key
74
+ def next
75
+ key @count += 1
76
+ end
77
+
78
+ private
79
+ # Spits out a key and run for a result
80
+ def key(count=count)
81
+ "#{count}:#{run}"
82
+ end
83
+ end
84
+
85
+ # Add evented functionality to a ping so that it times out, etc.
86
+ class Ping::Deferrable < Ping
87
+ include EventMachine::Deferrable
88
+
89
+ # Setup a ttl for the ping so that it will timeout after ttl seconds
90
+ def start_time
91
+ timeout(ttl) # Setup an em TTL on this thing so it fails if the thing isn't called
92
+ super
93
+ end
94
+
95
+ # Succeed a block passed into the ping and mark the ping as suceeded
96
+ def pong(&block)
97
+ callback(&block) if block_given?
98
+ super
99
+ succeed self
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,24 @@
1
+ module KingKong
2
+ # Opens a UNIX socket to report pinger statistics
3
+ class Server < EventMachine::Connection
4
+ Frame = "\r\n"
5
+
6
+ def initialize(pinger)
7
+ @pinger = pinger
8
+ end
9
+
10
+ def post_init
11
+ send_data frame @pinger.aggregator.to_hash.to_yaml
12
+ end
13
+
14
+ # Start an instance of the aggregator server on a unix port
15
+ def self.start(pinger, host='/tmp/kingkong.socket', port=nil)
16
+ EM.start_server host, port, self, pinger
17
+ end
18
+
19
+ private
20
+ def frame(message)
21
+ "#{message}#{Frame}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module KingKong
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kingkong
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brad Gessler
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-09-02 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: eventmachine
16
+ requirement: &70132736057580 !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: *70132736057580
25
+ description: Have you ever wanted to shoot a message throught Twitter, have your app
26
+ pick it up, do some work on it, and report how long it takes? KingKong makes it
27
+ slightly easier to do this with a DSL for writing custom pings and by providing
28
+ basic reporting facilities that plug into graphing applications like Munin.
29
+ email:
30
+ - brad@bradgessler.com
31
+ executables:
32
+ - kingkong-munin
33
+ - kingkong-server
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - .gitignore
38
+ - .rvmrc
39
+ - Gemfile
40
+ - README.md
41
+ - Rakefile
42
+ - bin/kingkong-munin
43
+ - bin/kingkong-server
44
+ - kingkong.gemspec
45
+ - lib/README.md
46
+ - lib/kingkong.rb
47
+ - lib/kingkong/aggregator.rb
48
+ - lib/kingkong/cli.rb
49
+ - lib/kingkong/logging.rb
50
+ - lib/kingkong/ping.rb
51
+ - lib/kingkong/server.rb
52
+ - lib/kingkong/version.rb
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project: kingkong
73
+ rubygems_version: 1.8.6
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Build complex network application health checks with Ruby and EventMachine
77
+ test_files: []