multi_ping 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1a67049a7ed2a315da0e452e3bfbd7877cd3895
4
+ data.tar.gz: 29ba4952467ef22c2fc2de87ea41486075f5bda9
5
+ SHA512:
6
+ metadata.gz: 3e915686ffbc1ea82c1e05e12d8d22aff290ebf34582c563f824f1b971c9b3a69eef0cb68d1ce6bc78a824ebd4325815005dc0a23575605ab99415e3f859cb48
7
+ data.tar.gz: 9c5fd2c0aa6ee19b553e920b7baf676ac5d7c663fdfe38de07e03e0e74afe8d03068c1f7aa00c645e99a06d7e194dfe07b9888d7afd7a7384abc8e0a8a0194c9
@@ -0,0 +1,10 @@
1
+ /.idea/
2
+ /.bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in multi_ping.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 genewoo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # multi_ping
2
+
3
+ For some reasons, you need to check network connection statics to more than one server.
4
+
5
+ ## Installation
6
+
7
+ Install it yourself as:
8
+
9
+ $ gem install multi_ping
10
+
11
+ ## Usage
12
+
13
+ You need to run ```multi_ping``` with a root privilege, ie. in rvm and sudo, ```rvmsudo multi_ping```
14
+
15
+ ```
16
+ Usage 1: multi_ping [options] hosts...
17
+ Usage 2: multi_ping [options] < host_file (one host each line)
18
+ Usage 3: echo hosts... || multi_ping [options]
19
+ -c, --count COUNT Ping Count
20
+ -p, --parallel PARALLEL Parallel running
21
+ -v, --verbose Print log verbose
22
+ -t, --threashold COUNT Stop ping once reach the threashold
23
+ ```
24
+
25
+ ## Sample Output
26
+
27
+ It will stop ping the host once 1/5 or total count of pacage was dropped
28
+
29
+ ```
30
+ tw.sina.com.cn, 90.2926, 100.0
31
+ sg.sina.com.cn, 97.802, 100.0
32
+ jp.sina.com.cn, 113.5288, 100.0
33
+ hk.sina.com.cn, 179.8547, 100.0
34
+ us.sina.com.cn, 264.4235, 100.0
35
+ uk.sina.com.cn, 297.1144, 100.0
36
+ nothing.nil, 9999.0, 0.0
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/genewoo/multi_ping. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
53
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "multi_ping"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ # puts ARGF.read
14
+
15
+ require 'optparse'
16
+
17
+ options = {}
18
+ OptionParser.new do |opts|
19
+ opts.banner = <<BANNER
20
+ Usage 1: multi_ping [options] hosts...
21
+ Usage 2: multi_ping [options] < host_file (one host each line)
22
+ Usage 3: echo hosts... || multi_ping [options]
23
+ BANNER
24
+ opts.on('-c', '--count COUNT', 'Ping Count') { |v| options[:count] = v }
25
+ opts.on('-p', '--parallel PARALLEL', 'Parallel running') { |v| options[:parallel] = v }
26
+ opts.on('-v', '--verbose', 'Print log verbose') { options[:verbose] = true}
27
+ opts.on('-t', '--threshold COUNT', 'Stop ping once reach the threshold') {|v| options[:threshold] = v}
28
+ end.parse!
29
+
30
+ options[:hosts] = []
31
+
32
+ if $stdin.tty?
33
+ options[:hosts] = ARGV
34
+ else
35
+ ARGF.each do |line|
36
+ options[:hosts] << line
37
+ end
38
+ end
39
+
40
+ processor = MultiPing::Processor.new(options).process
41
+ processor.results.map{|k,v| puts "#{k}, #{v[0].round(4)}, #{v[1].round(2)}"}
@@ -0,0 +1,73 @@
1
+ require "multi_ping/version"
2
+ require 'net/ping'
3
+ require 'thread'
4
+
5
+ module MultiPing
6
+ # Your code goes here...
7
+
8
+ DEFAULT = {
9
+ count: 20,
10
+ parallel: 2
11
+ }
12
+
13
+ class Processor
14
+
15
+ # attr_accessor :results
16
+
17
+ def initialize(options={})
18
+ @count = options.fetch :count, MultiPing::DEFAULT[:count]
19
+ @count = @count.to_i if @count.kind_of? String
20
+ @parallel = options.fetch :parallel, MultiPing::DEFAULT[:parallel]
21
+ @verbose = options.fetch :verbose, false
22
+ @threshold = options.fetch :threshold, @count
23
+ @threshold = @threshold.to_i if @threshold.kind_of? String
24
+ @hosts = options.fetch :hosts, []
25
+ @results = {}
26
+ @queue = Queue.new
27
+ @hosts.each { |host| @queue << host }
28
+ end
29
+
30
+
31
+ def process
32
+ workers = (0..@parallel.to_i).map do
33
+ Thread.new do
34
+ begin
35
+ while host = @queue.pop(true)
36
+ host = host.gsub("\n", '')
37
+ icmp = Net::Ping::ICMP.new(host)
38
+ rtary = []
39
+ pingfails = 0
40
+ # puts 'starting to ping'
41
+ (1..@count).each do
42
+ if icmp.ping
43
+ rtary << icmp.duration
44
+ else
45
+ pingfails += 1
46
+ if pingfails >= @threshold
47
+ pingfails = @count # make it all failed
48
+ break
49
+ end
50
+ end
51
+ end
52
+ if pingfails < @count
53
+ avg = rtary.inject(0) {|sum, i| sum + i} * 1000/(@count - pingfails)
54
+ quality = pingfails == 0 ? "Perfect!":"#{pingfails} within #{@count} packets were droped"
55
+ puts "#{host} | Response Time : #{avg.round(2)} ms | #{quality}" if @verbose
56
+ @results[host] = [avg, (@count - pingfails) * 100.0 / @count]
57
+ else
58
+ @results[host] = [9999, 0.0]
59
+ end
60
+ end
61
+ rescue ThreadError
62
+ end
63
+ end
64
+ end
65
+ workers.map(&:join)
66
+ self
67
+ end
68
+
69
+ def results
70
+ @results.sort_by{|k,v| v[1] * - 100 - 100 / v[0]}
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,3 @@
1
+ module MultiPing
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'multi_ping/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "multi_ping"
8
+ spec.version = MultiPing::VERSION
9
+ spec.authors = ["genewoo"]
10
+ spec.email = ["genewoo_AT_gmail.com"]
11
+
12
+ spec.summary = %q{Ping Multiple Nodes Concurrently}
13
+ spec.description = %q{Check network quality by sending ICMP package concurrently.}
14
+ spec.homepage = "https://github.com/genewoo/multi_ping"
15
+ spec.license = "MIT"
16
+
17
+ spec.required_ruby_version = '>= 2.2.2'
18
+ spec.required_rubygems_version = '>= 1.8.11'
19
+
20
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency('net-ping', '>= 1.7.6')
26
+ spec.add_development_dependency "bundler", "~> 1.10"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "minitest"
29
+ spec.add_development_dependency "pry"
30
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: multi_ping
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - genewoo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: net-ping
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 1.7.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Check network quality by sending ICMP package concurrently.
84
+ email:
85
+ - genewoo_AT_gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/multi_ping
98
+ - lib/multi_ping.rb
99
+ - lib/multi_ping/version.rb
100
+ - multi_ping.gemspec
101
+ homepage: https://github.com/genewoo/multi_ping
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: 2.2.2
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: 1.8.11
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.6
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Ping Multiple Nodes Concurrently
125
+ test_files: []
126
+ has_rdoc: