pong 0.1.0 → 0.2.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.
- data/History.txt +7 -3
- data/config/hoe.rb +0 -1
- data/lib/pong.rb +35 -4
- data/lib/pong/version.rb +1 -1
- data/test/test_series.rb +37 -0
- metadata +3 -2
data/History.txt
CHANGED
@@ -1,4 +1,8 @@
|
|
1
|
-
== 0.0
|
1
|
+
== 0.2.0 2007-09-23
|
2
|
+
|
3
|
+
fill out ping arrays, so that a ping that's lasted more than one second counts as a miss (until it actually returns)
|
4
|
+
|
5
|
+
== 0.1.0
|
6
|
+
|
7
|
+
give buffer a maximum size (one hour)
|
2
8
|
|
3
|
-
* 1 major enhancement:
|
4
|
-
* Initial release
|
data/config/hoe.rb
CHANGED
@@ -27,7 +27,6 @@ Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
|
27
27
|
RUBYFORGE_USERNAME.replace @config["username"]
|
28
28
|
end
|
29
29
|
|
30
|
-
|
31
30
|
REV = nil
|
32
31
|
# UNCOMMENT IF REQUIRED:
|
33
32
|
# REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
|
data/lib/pong.rb
CHANGED
@@ -5,10 +5,32 @@ require "fileutils"
|
|
5
5
|
|
6
6
|
module Pong
|
7
7
|
class Series < Array
|
8
|
-
MAX =
|
8
|
+
MAX = 3600 # only save an hour of pings
|
9
|
+
|
10
|
+
def initialize(max = MAX)
|
11
|
+
@max = max
|
12
|
+
@offset = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
def squeeze
|
16
|
+
while size >= @max
|
17
|
+
shift
|
18
|
+
@offset += 1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def []=(i, val)
|
23
|
+
squeeze
|
24
|
+
super(i-@offset, val)
|
25
|
+
end
|
26
|
+
|
27
|
+
def [](i)
|
28
|
+
squeeze
|
29
|
+
super(i-@offset)
|
30
|
+
end
|
9
31
|
|
10
32
|
def num(n)
|
11
|
-
n =
|
33
|
+
n = @max if n.nil?
|
12
34
|
[n, size].min
|
13
35
|
end
|
14
36
|
|
@@ -24,7 +46,7 @@ module Pong
|
|
24
46
|
end
|
25
47
|
|
26
48
|
def mean(n = MAX)
|
27
|
-
size == 0 ? 0 : sum(n) / num(n)
|
49
|
+
size == 0 ? 0 : sum(n).to_f / num(n)
|
28
50
|
end
|
29
51
|
|
30
52
|
def nils(n = MAX)
|
@@ -70,6 +92,11 @@ module Pong
|
|
70
92
|
end
|
71
93
|
end
|
72
94
|
|
95
|
+
def at_least(n)
|
96
|
+
# this fills out the array with nils if it needs to
|
97
|
+
@pings[n] = @pings[n] unless n < 0
|
98
|
+
end
|
99
|
+
|
73
100
|
def missing(n=nil)
|
74
101
|
pings.nils(n)
|
75
102
|
end
|
@@ -112,7 +139,8 @@ module Pong
|
|
112
139
|
end
|
113
140
|
|
114
141
|
def stats(n = nil)
|
115
|
-
|
142
|
+
n = first.pings.size if n.nil?
|
143
|
+
puts "Last #{n} seconds:"
|
116
144
|
puts first.header
|
117
145
|
self.each do |host|
|
118
146
|
puts host.stats(n)
|
@@ -120,8 +148,11 @@ module Pong
|
|
120
148
|
end
|
121
149
|
|
122
150
|
def run
|
151
|
+
start = Time.now
|
123
152
|
each {|host| host.start }
|
124
153
|
while true
|
154
|
+
secs_since_starting = Time.now - start
|
155
|
+
each {|host| host.at_least(secs_since_starting - 1) }
|
125
156
|
system("clear")
|
126
157
|
stats(10)
|
127
158
|
puts
|
data/lib/pong/version.rb
CHANGED
data/test/test_series.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
|
3
|
+
|
4
|
+
class TestSeries < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_only_fill_up_to_max
|
7
|
+
series = Pong::Series.new(2)
|
8
|
+
series[0] = 1
|
9
|
+
series[1] = 2
|
10
|
+
series[2] = 3
|
11
|
+
assert_equal 2.5, series.mean
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_sum
|
15
|
+
series = Pong::Series.new
|
16
|
+
series[0] = 3
|
17
|
+
assert_equal 3, series.sum
|
18
|
+
series[1] = 6
|
19
|
+
assert_equal 9, series.sum
|
20
|
+
series[2] = 9
|
21
|
+
assert_equal 18, series.sum
|
22
|
+
|
23
|
+
assert_equal 15, series.sum(2)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_mean
|
27
|
+
series = Pong::Series.new
|
28
|
+
series[0] = 3
|
29
|
+
assert_equal 3, series.mean
|
30
|
+
series[1] = 6
|
31
|
+
assert_equal 4.5, series.mean
|
32
|
+
series[2] = 9
|
33
|
+
assert_equal 6, series.mean
|
34
|
+
|
35
|
+
assert_equal 7.5, series.mean(2)
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: pong
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2007-09-
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-09-23 00:00:00 -07:00
|
8
8
|
summary: pong is a wrapper for ping that adds statistics over time, multiple hosts, etc.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
test_files:
|
53
53
|
- test/test_helper.rb
|
54
54
|
- test/test_pong.rb
|
55
|
+
- test/test_series.rb
|
55
56
|
rdoc_options:
|
56
57
|
- --main
|
57
58
|
- README.txt
|