pong 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,8 +1,11 @@
1
- == 0.2.0 2007-09-23
1
+ === 0.3.0 / 2008-04-06
2
+
3
+ Perform a DNS Resolve before starting ping (to help tease apart DNS issues from other network issues)
4
+
5
+ === 0.2.0 / 2007-09-23
2
6
 
3
7
  fill out ping arrays, so that a ping that's lasted more than one second counts as a miss (until it actually returns)
4
8
 
5
- == 0.1.0
9
+ === 0.1.0
6
10
 
7
11
  give buffer a maximum size (one hour)
8
-
@@ -4,17 +4,7 @@ Manifest.txt
4
4
  README.txt
5
5
  Rakefile
6
6
  bin/pong
7
- config/hoe.rb
8
- config/requirements.rb
9
7
  lib/pong.rb
10
8
  lib/pong/version.rb
11
- log/debug.log
12
- script/destroy
13
- script/generate
14
- script/txt2html
15
- setup.rb
16
- tasks/deployment.rake
17
- tasks/environment.rake
18
- tasks/website.rake
19
9
  test/test_helper.rb
20
10
  test/test_pong.rb
data/README.txt CHANGED
@@ -1 +1,40 @@
1
- README
1
+ = pong
2
+
3
+ * http://blabs.pivotallabs.com/users/alex/blog/articles/286-pong
4
+
5
+ == DESCRIPTION:
6
+
7
+ Pong is Ruby app that runs ping in the background on several hosts at once, and decorates the results, tracking statistics in realtime, refreshing the screen every 5 seconds.
8
+
9
+ == SYNOPSIS:
10
+
11
+ pong localhost 192.168.1.240 192.168.1.1 google.com yahoo.com pivotalblabs.com
12
+
13
+ == INSTALL:
14
+
15
+ gem install pong
16
+
17
+ == LICENSE:
18
+
19
+ (The MIT License)
20
+
21
+ Copyright (c) 2008 Alex Chaffee
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining
24
+ a copy of this software and associated documentation files (the
25
+ 'Software'), to deal in the Software without restriction, including
26
+ without limitation the rights to use, copy, modify, merge, publish,
27
+ distribute, sublicense, and/or sell copies of the Software, and to
28
+ permit persons to whom the Software is furnished to do so, subject to
29
+ the following conditions:
30
+
31
+ The above copyright notice and this permission notice shall be
32
+ included in all copies or substantial portions of the Software.
33
+
34
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
35
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
36
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
37
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
38
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
39
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
40
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'config/requirements'
2
2
  require 'config/hoe' # setup Hoe + all gem configuration
3
3
 
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
4
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
5
+
@@ -1,7 +1,11 @@
1
1
  $:.unshift File.dirname(__FILE__)
2
2
 
3
3
  # Pong version 0.1 by Alex Chaffee
4
+
5
+ # todo: http://blog.nominet.org.uk/tech/category/ruby/
6
+
4
7
  require "fileutils"
8
+ require "resolv-replace"
5
9
 
6
10
  module Pong
7
11
  class Series < Array
@@ -59,25 +63,49 @@ module Pong
59
63
  end
60
64
 
61
65
  class Host
62
- attr_reader :pings, :hostname, :address
66
+ attr_reader :pings, :hostname, :status
63
67
 
64
68
  def initialize(hostname)
65
- @hostname = @address = hostname
69
+ @hostname = hostname
70
+ @address = hostname if hostname =~ /^[0-9\.]*$/
71
+ @address = "127.0.0.1" if hostname == "localhost"
66
72
  @output = "/tmp/#{hostname}.out"
67
73
  FileUtils.rm_rf(@output) if File.exist?(@output)
68
74
  FileUtils.touch(@output)
69
75
  end
70
-
76
+
77
+ def address
78
+ @address || "?"
79
+ end
80
+
71
81
  def start
72
82
  @pings = Series.new
73
- process = IO.popen("ping #{hostname}")
74
83
  Thread.new do
84
+ resolve_address
85
+ process = IO.popen("ping #{address}")
75
86
  while (line = process.gets)
76
87
  parse(line) unless line.nil?
77
88
  end
78
89
  end
79
90
  end
80
91
 
92
+ def resolve_address
93
+ while @address.nil?
94
+ begin
95
+ @status = "Resolving..."
96
+ @address = Resolv::DNS.new.getaddresses(hostname).first
97
+ if @address.nil?
98
+ @status = "Resolve failed"
99
+ sleep 5
100
+ else
101
+ @status = nil
102
+ end
103
+ rescue => e
104
+ @status = e.to_s
105
+ sleep 5
106
+ end
107
+ end
108
+ end
81
109
  def parse(line)
82
110
  m = /^PING (\S*) \(([0-9.]*)\)/.match(line)
83
111
  unless m.nil?
@@ -114,6 +142,7 @@ module Pong
114
142
  "%8.3f msec" % (mean(n)),
115
143
  "%4d (%.2f%%)" % [missing(n), missing_percent(n)],
116
144
  "#{hostname} (#{address})",
145
+ "#{status}",
117
146
  ].join("\t")
118
147
  end
119
148
 
@@ -159,7 +188,7 @@ module Pong
159
188
  stats(60)
160
189
  puts
161
190
  stats
162
- sleep(5)
191
+ sleep(2)
163
192
  end
164
193
  end
165
194
  end
@@ -1,7 +1,7 @@
1
1
  module Pong #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
4
+ MINOR = 3
5
5
  TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,33 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
3
- specification_version: 1
4
2
  name: pong
5
3
  version: !ruby/object:Gem::Version
6
- version: 0.2.0
7
- date: 2007-09-23 00:00:00 -07:00
8
- summary: pong is a wrapper for ping that adds statistics over time, multiple hosts, etc.
9
- require_paths:
10
- - lib
11
- email: alex@pivotallabs.com
12
- homepage: http://pivotalrb.rubyforge.org
13
- rubyforge_project: pivotalrb
14
- description: pong is a wrapper for ping that adds statistics over time, multiple hosts, etc.
15
- autorequire:
16
- default_executable: pong
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
4
+ version: 0.3.0
25
5
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
6
  authors:
30
7
  - Alex Chaffee
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-04-06 00:00:00 -07:00
13
+ default_executable: pong
14
+ dependencies: []
15
+
16
+ description: Pong is Ruby app that runs ping in the background on several hosts at once, and decorates the results, tracking statistics in realtime, refreshing the screen every 5 seconds.
17
+ email: alex@pivotallabs.com
18
+ executables:
19
+ - pong
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - License.txt
25
+ - Manifest.txt
26
+ - README.txt
31
27
  files:
32
28
  - History.txt
33
29
  - License.txt
@@ -35,37 +31,38 @@ files:
35
31
  - README.txt
36
32
  - Rakefile
37
33
  - bin/pong
38
- - config/hoe.rb
39
- - config/requirements.rb
40
34
  - lib/pong.rb
41
35
  - lib/pong/version.rb
42
- - log/debug.log
43
- - script/destroy
44
- - script/generate
45
- - script/txt2html
46
- - setup.rb
47
- - tasks/deployment.rake
48
- - tasks/environment.rake
49
- - tasks/website.rake
50
- - test/test_helper.rb
51
- - test/test_pong.rb
52
- test_files:
53
36
  - test/test_helper.rb
54
37
  - test/test_pong.rb
55
- - test/test_series.rb
38
+ has_rdoc: true
39
+ homepage: http://pivotalrb.rubyforge.org
40
+ post_install_message:
56
41
  rdoc_options:
57
42
  - --main
58
43
  - README.txt
59
- extra_rdoc_files:
60
- - History.txt
61
- - License.txt
62
- - Manifest.txt
63
- - README.txt
64
- executables:
65
- - pong
66
- extensions: []
67
-
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ version:
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
68
58
  requirements: []
69
59
 
70
- dependencies: []
71
-
60
+ rubyforge_project: pivotalrb
61
+ rubygems_version: 1.0.1
62
+ signing_key:
63
+ specification_version: 2
64
+ summary: Pong is Ruby app that runs ping in the background on several hosts at once, and decorates the results, tracking statistics in realtime, refreshing the screen every 5 seconds.
65
+ test_files:
66
+ - test/test_helper.rb
67
+ - test/test_pong.rb
68
+ - test/test_series.rb
@@ -1,74 +0,0 @@
1
- require 'pong/version'
2
-
3
- AUTHOR = 'Alex Chaffee' # can also be an array of Authors
4
- EMAIL = "alex@pivotallabs.com"
5
- DESCRIPTION = "pong is a wrapper for ping that adds statistics over time, multiple hosts, etc."
6
- GEM_NAME = 'pong' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'pivotalrb' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
-
11
- @config_file = "~/.rubyforge/user-config.yml"
12
- @config = nil
13
- RUBYFORGE_USERNAME = "unknown"
14
- def rubyforge_username
15
- unless @config
16
- begin
17
- @config = YAML.load(File.read(File.expand_path(@config_file)))
18
- rescue
19
- puts <<-EOS
20
- ERROR: No rubyforge config file found: #{@config_file}"
21
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
- - See http://newgem.rubyforge.org/rubyforge.html for more details
23
- EOS
24
- exit
25
- end
26
- end
27
- RUBYFORGE_USERNAME.replace @config["username"]
28
- end
29
-
30
- REV = nil
31
- # UNCOMMENT IF REQUIRED:
32
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
33
- VERS = Pong::VERSION::STRING + (REV ? ".#{REV}" : "")
34
- RDOC_OPTS = ['--quiet', '--title', 'pong documentation',
35
- "--opname", "index.html",
36
- "--line-numbers",
37
- "--main", "README",
38
- "--inline-source"]
39
-
40
- class Hoe
41
- def extra_deps
42
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
43
- @extra_deps
44
- end
45
- end
46
-
47
- # Generate all the Rake tasks
48
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
49
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
50
- p.author = AUTHOR
51
- p.description = DESCRIPTION
52
- p.email = EMAIL
53
- p.summary = DESCRIPTION
54
- p.url = HOMEPATH
55
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
- p.test_globs = ["test/**/test_*.rb"]
57
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
-
59
- # == Optional
60
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\\n\\n")
61
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
-
63
- p.spec_extras = {
64
- :bindir => 'bin',
65
- :executables => ['pong'],
66
- :default_executable => 'pong',
67
-
68
- } # A hash of extra values to set in the gemspec.
69
-
70
- end
71
-
72
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
73
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
74
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
@@ -1,17 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe newgem rubigen].each do |req_gem|
6
- begin
7
- require req_gem
8
- rescue LoadError
9
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
- puts "Installation: gem install #{req_gem} -y"
11
- exit
12
- end
13
- end
14
-
15
- $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
-
17
- require 'pong'
File without changes
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.join(File.dirname(__FILE__), '..')
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
@@ -1,74 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- begin
5
- require 'newgem'
6
- rescue LoadError
7
- puts "\n\nGenerating the website requires the newgem RubyGem"
8
- puts "Install: gem install newgem\n\n"
9
- exit(1)
10
- end
11
- require 'redcloth'
12
- require 'syntax/convertors/html'
13
- require 'erb'
14
- require File.dirname(__FILE__) + '/../lib/pong/version.rb'
15
-
16
- version = Pong::VERSION::STRING
17
- download = 'http://rubyforge.org/projects/pong'
18
-
19
- class Fixnum
20
- def ordinal
21
- # teens
22
- return 'th' if (10..19).include?(self % 100)
23
- # others
24
- case self % 10
25
- when 1: return 'st'
26
- when 2: return 'nd'
27
- when 3: return 'rd'
28
- else return 'th'
29
- end
30
- end
31
- end
32
-
33
- class Time
34
- def pretty
35
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
- end
37
- end
38
-
39
- def convert_syntax(syntax, source)
40
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
- end
42
-
43
- if ARGV.length >= 1
44
- src, template = ARGV
45
- template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
-
47
- else
48
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
- exit!
50
- end
51
-
52
- template = ERB.new(File.open(template).read)
53
-
54
- title = nil
55
- body = nil
56
- File.open(src) do |fsrc|
57
- title_text = fsrc.readline
58
- body_text = fsrc.read
59
- syntax_items = []
60
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
- ident = syntax_items.length
62
- element, syntax, source = $1, $2, $3
63
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
- "syntax-temp-#{ident}"
65
- }
66
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
- body = RedCloth.new(body_text).to_html
68
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
- end
70
- stat = File.stat(src)
71
- created = stat.ctime
72
- modified = stat.mtime
73
-
74
- $stdout << template.result(binding)