ping2v 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2c558329b2f17335838fd63119a14f5d672302e
4
+ data.tar.gz: 7baddf71018dd915fb47ec0e7d66aa08ac92c8ad
5
+ SHA512:
6
+ metadata.gz: 03b580e1a0206e2e19742901d73046f512bd85a8b72b425d7b3d45fc75b088ea47f506143e608d8beb2800a419d8db81fef367f5957d4b9c1727fb3752e4a463
7
+ data.tar.gz: 030a1778f90336df828ed4e6b90e1cb6ba4f8a434b1e75bde55670a3d896da877d44959e33e148269f14affb5e8a96ef08513c21dafd170ff15850de3bfbe85c
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ping2v.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Masa Mizutani
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Ping2v
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'ping2v'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install ping2v
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( https://github.com/[my-github-username]/ping2v/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/ping2v ADDED
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+
4
+ require 'open3'
5
+ require 'optparse'
6
+ require 'eventmachine'
7
+ require 'json'
8
+ require 'net/http'
9
+ require 'pp'
10
+ require 'launchy'
11
+ require 'socket'
12
+ require 'yaml'
13
+
14
+ class Recver < EventMachine::Connection
15
+ def initialize(a)
16
+ @arr = a
17
+ end
18
+
19
+ def receive_data(data)
20
+ line = data
21
+ res = line.scan(/^(\d+) bytes from (\S+?): icmp_[a-z]+=(\d+) ttl=(\d+) time=([\d\.]+) ms$/)
22
+ p line if res.size == 0
23
+ res.each do |r|
24
+ m = {
25
+ 'ts' => Time.now.to_f,
26
+ 'size' => r[0].to_i,
27
+ 'src' => @ipaddr,
28
+ 'dst' => r[1],
29
+ 'seq' => r[2].to_i,
30
+ 'ttl' => r[3].to_i,
31
+ 'rtt' => r[4].to_f
32
+ }
33
+ @arr.push(m)
34
+ end
35
+ end
36
+
37
+ def unbind
38
+ EM.stop_event_loop
39
+ end
40
+ end
41
+
42
+ class Stream
43
+ attr_accessor :open_browser, :dst, :src
44
+
45
+ def initialize(host, port)
46
+ @open_browser = true
47
+ @stream_id = nil
48
+ @host = host
49
+ @port = port
50
+ end
51
+
52
+ def submit(arr)
53
+ return nil if arr.size == 0
54
+
55
+ data = calc(arr, 'rtt')
56
+ dst = (arr.inject([]) {|a, m| a.push(m['dst'])}).uniq.join(', ')
57
+ hdr = { 'Content-Type' => 'application/json' }
58
+ hdr['stream-id'] = @stream_id unless @stream_id.nil?
59
+ http = Net::HTTP.new(@host, @port)
60
+ req = Net::HTTP::Post.new('/stream', initheader = hdr)
61
+
62
+ req.body = {
63
+ 'meta' => {
64
+ 'ts' => Time.now.to_f,
65
+ 'dst' => dst,
66
+ 'src' => @src,
67
+ },
68
+ 'data' => data,
69
+ }.to_json
70
+
71
+ begin
72
+ res = http.start {|h| h.request(req)}
73
+ if res.code.to_i == 201
74
+ r = JSON.parse(res.body)
75
+ if @stream_id.nil?
76
+ if @port == 80
77
+ url = "http://#{@host}/view/#{r['view_id']}"
78
+ else
79
+ url = "http://#{@host}:#{@port}/view/#{r['view_id']}"
80
+ end
81
+ p url
82
+ Launchy.open(url) if @open_browser
83
+ end
84
+ @stream_id = r['stream_id']
85
+ else
86
+ @stream_id = nil
87
+ end
88
+ rescue => e
89
+ p e
90
+ end
91
+ end
92
+
93
+ def calc(data, tgt)
94
+ arr = data.inject([]) {|arr, m| arr.push(m[tgt])}
95
+ msg = {}
96
+ msg['avg'] = arr.inject(0.0) {|r,i| r += i } / arr.size
97
+ msg['min'] = arr.min
98
+ msg['max'] = arr.max
99
+ # msg['count'] = arr.size
100
+ # msg['amount'] = arr.inject(:+)
101
+ if arr.size % 2 == 0
102
+ c = (arr.size / 2)
103
+ msg['mid'] = arr[c - 1, 2].inject(:+) / 2.0
104
+ # msg['q1'] = arr[c/2 - 1, 2].inject(:+) / 2.0
105
+ # msg['q3'] = arr[c/2 + c, 2].inject(:+) / 2.0
106
+ else
107
+ c = ((arr.size + 1) / 2)
108
+ msg['mid'] = arr[c]
109
+ # msg['q1'] = arr[(c+1)/2]
110
+ # msg['q3'] = arr[(c+arr.size)/2]
111
+ end
112
+
113
+ return msg
114
+ end
115
+ end
116
+
117
+
118
+
119
+ interval = 1
120
+ flood = false
121
+ server = 'ping2v.ng.bluemix.net'
122
+ port = 80
123
+
124
+ unless ENV['HOME'].nil?
125
+ conf_path = File.join(ENV['HOME'], '.ping2v.yml')
126
+ if File.exists?(conf_path)
127
+ conf = File.open(conf_path, 'r') {|fd| YAML.load(fd) }
128
+ server = conf['server'] unless conf['server'].nil?
129
+ port = conf['port'].to_i unless conf['port'].nil?
130
+ end
131
+ end
132
+
133
+ ins = Stream.new(server, port)
134
+
135
+ opt = OptionParser.new
136
+ opt.on('-i VAL') {|v| interval = v.to_i }
137
+ opt.on('-d') {|v| ins.open_browser = false }
138
+ # opt.on('-f') {|v| flood = true }
139
+ argv = opt.parse(ARGV)
140
+
141
+ arr = []
142
+
143
+ ins.dst = argv[0]
144
+ ins.src = Socket::gethostname
145
+ begin
146
+ src_addr = Socket.getaddrinfo(ins.src, nil, Socket::AF_INET)[0][3]
147
+ ins.src = src_addr unless src_addr.nil?
148
+ rescue => e
149
+ p e
150
+ end
151
+
152
+ EM.run do
153
+ EM.add_periodic_timer(interval) do
154
+ ins.submit(arr)
155
+ arr.clear
156
+ end
157
+
158
+ cmd = "ping -i 0.2 #{argv[0]}"
159
+ stdin, stdout, stderr = Open3.popen3(cmd)
160
+ stdout.sync = true
161
+ EM.attach(stdout, Recver, arr)
162
+ end
163
+
@@ -0,0 +1,3 @@
1
+ module Ping2v
2
+ VERSION = "0.0.2"
3
+ end
data/lib/ping2v.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "ping2v/version"
2
+
3
+ module Ping2v
4
+ # Your code goes here...
5
+ end
data/ping2v.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ping2v/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ping2v"
8
+ spec.version = Ping2v::VERSION
9
+ spec.authors = ["Masa Mizutani"]
10
+ spec.email = ["mizutani@sfc.wide.ad.jp"]
11
+ spec.summary = %q{Instantly Visualization Tool for Ping}
12
+ spec.description = %q{Executing ping command and upload the result to Web Server, and visualize a line chart for Maximum, Minimum, Agerage and Median of RTT}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables << 'ping2v'
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "eventmachine"
24
+ spec.add_dependency "launchy"
25
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ping2v
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Masa Mizutani
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: eventmachine
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: launchy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Executing ping command and upload the result to Web Server, and visualize
70
+ a line chart for Maximum, Minimum, Agerage and Median of RTT
71
+ email:
72
+ - mizutani@sfc.wide.ad.jp
73
+ executables:
74
+ - ping2v
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/ping2v
84
+ - lib/ping2v.rb
85
+ - lib/ping2v/version.rb
86
+ - ping2v.gemspec
87
+ homepage: ''
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Instantly Visualization Tool for Ping
111
+ test_files: []