fluent-plugin-network-probe 0.0.1

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: fc2a98b51c2a9854113057dccad5cfbf17585f3f
4
+ data.tar.gz: c7e9132c1fa5b8270208905de9f6ea1995e57658
5
+ SHA512:
6
+ metadata.gz: ec9e4e3bbc906c397c4301492f4bcdd8a843bfbf08f95c5df290636d7056a69993cdef206d7792696df3957227a12617aa2886828282980e156601e028df8e68
7
+ data.tar.gz: bdeaaf68ae983121038167aefa698fe96ce34fdbdbbd685c28a94f43371501f6b2d66cbe504a97930f4e8ac61795e2f8280654797456379dc31392ac0334b10c
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
19
+ vendor/*
20
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
data/Gemfile.lock ADDED
@@ -0,0 +1,32 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fluent-plugin-network-probe (0.0.1)
5
+ eventmachine
6
+ fluentd (>= 0.10.7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ cool.io (1.1.1)
12
+ iobuffer (>= 1.0.0)
13
+ eventmachine (1.0.3)
14
+ fluentd (0.10.40)
15
+ cool.io (~> 1.1.1)
16
+ http_parser.rb (~> 0.5.1)
17
+ json (>= 1.4.3)
18
+ msgpack (>= 0.4.4, < 0.6.0, != 0.5.3, != 0.5.2, != 0.5.1, != 0.5.0)
19
+ yajl-ruby (~> 1.0)
20
+ http_parser.rb (0.5.3)
21
+ iobuffer (1.1.2)
22
+ json (1.8.1)
23
+ msgpack (0.5.6)
24
+ rake (10.1.0)
25
+ yajl-ruby (1.1.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ fluent-plugin-network-probe!
32
+ rake
data/README.textile ADDED
@@ -0,0 +1,72 @@
1
+ h1. Fluent::Plugin::NetworkProbe
2
+
3
+ Fluentd input plugin to probe network latency and keepalive, similar to Smokeping.
4
+ Now support methods are fping and curl.
5
+
6
+
7
+ h2. Installation
8
+
9
+ h3. Install tools
10
+
11
+ on Ubuntu12.04
12
+
13
+ <pre>
14
+ $ sudo apt-get install fping curl
15
+ </pre>
16
+
17
+ h3. Install fluent plugin
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ <pre>
22
+ gem 'fluent-plugin-network-probe'
23
+ </pre>
24
+
25
+ Or install it yourself as:
26
+
27
+ <pre>
28
+ $ gem install fluent-plugin-network-probe
29
+ </pre>
30
+
31
+ Or use td-agent : (on Ubuntu12.04)
32
+
33
+ <pre>
34
+ $ sudo /usr/lib/fluent/ruby/bin/fluent-gem install fluent-plugin-network-probe
35
+ </pre>
36
+
37
+
38
+
39
+ h2. Configuration
40
+
41
+ <pre>
42
+ <source>
43
+ type config_expander
44
+
45
+ <config>
46
+ type network_probe
47
+ probe_type fping
48
+ target google.com
49
+ tag network_probe.${hostname}.fping
50
+ fping_count 5 # optional: default 5(count)
51
+ fping_timeout 2 # optional: default 2(sec)
52
+ fping_interval 1 # optional: default 1(sec)
53
+ fping_path /usr/bin/fping # optional: default '/usr/bin/fping'
54
+ </config>
55
+ </source>
56
+
57
+ <source>
58
+ type config_expander
59
+
60
+ <config>
61
+ type network_probe
62
+ probe_type curl
63
+ target google.com
64
+ tag network_probe.${hostname}.curl
65
+ curl_count 5 # optional: default 5(count)
66
+ curl_timeout 2 # optional: default 2(sec)
67
+ curl_interval 1 # optional: default 1(sec)
68
+ curl_path /usr/bin/curl # optional: default '/usr/bin/curl'
69
+ </config>
70
+ </source>
71
+ </pre>
72
+
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rake/testtask'
5
+ Rake::TestTask.new(:test) do |test|
6
+ test.libs << 'lib' << 'test'
7
+ test.pattern = 'test/**/test_*.rb'
8
+ test.test_files = Dir['test/plugin/*.rb']
9
+ test.ruby_opts = ['-rubygems'] if defined? Gem
10
+ test.ruby_opts << '-I.'
11
+ test.verbose = true
12
+ end
13
+
14
+ task :default => :test
15
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-network-probe"
6
+ gem.version = File.read("VERSION").strip
7
+ gem.authors = ["Yuichi UEMURA"]
8
+ gem.email = ["yuichi.u@gmail.com"]
9
+ gem.homepage = "https://github.com/u-ichi/fluent-plugin-network-probe"
10
+ gem.summary = %q{Fluentd input plugin to probe network latency and keepalive, similar to smokeping}
11
+ gem.description = %q{Fluentd input plugin to probe network latency and keepalive, similar to smokeping}
12
+
13
+ gem.files = `git ls-files`.split("\n")
14
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ gem.require_paths = ["lib"]
17
+
18
+ gem.add_dependency "fluentd", ">= 0.10.7"
19
+ gem.add_dependency "eventmachine"
20
+
21
+ gem.add_development_dependency "rake"
22
+ end
23
+
@@ -0,0 +1,133 @@
1
+ module Fluent
2
+ class NetworkProbeInput < Input
3
+ Fluent::Plugin.register_input("network_probe", self)
4
+
5
+ config_param :probe_type
6
+ config_param :target
7
+
8
+ config_param :interval, :default => 60 # sec
9
+
10
+ config_param :fping_count, :default => 5 # number
11
+ config_param :fping_timeout, :default => 2 # sec
12
+ config_param :fping_interval, :default => 1 # sec
13
+ config_param :fping_path, :default => '/usr/bin/fping'
14
+
15
+ config_param :curl_count, :default => 5 # number
16
+ config_param :curl_timeout, :default => 2 # sec
17
+ config_param :curl_interval, :default => 1 # sec
18
+ config_param :curl_path, :default => '/usr/bin/curl'
19
+
20
+ config_param :tag, :default => "network_probe"
21
+ config_param :debug_mode, :default => false
22
+
23
+ def initialize
24
+ require "eventmachine"
25
+
26
+ super
27
+ end
28
+
29
+ def configure(conf)
30
+ super
31
+
32
+ @conf = conf
33
+ end
34
+
35
+ def start
36
+ super
37
+ @thread = Thread.new(&method(:run))
38
+ $log.info "starting network probe, target #{@target} probe_type #{@probe_type}."
39
+ end
40
+
41
+ def shutdown
42
+ super
43
+ @thread.kill
44
+ end
45
+
46
+ def run
47
+ init_eventmachine
48
+ EM.run do
49
+ EM.add_periodic_timer(@interval) do
50
+ begin
51
+ EM.defer do
52
+ Engine.emit("#{@tag}_#{@target}", Engine.now, exec_fping) if @probe_type == 'fping'
53
+ end
54
+ EM.defer do
55
+ Engine.emit("#{@tag}_#{@target}", Engine.now, exec_curl) if @probe_type == 'curl'
56
+ end
57
+ rescue => ex
58
+ $log.warn("EM.periodic_timer loop error.")
59
+ $log.warn("#{ex}, tracelog : \n#{ex.backtrace.join("\n")}")
60
+ end
61
+ end
62
+ end
63
+ end
64
+
65
+ def exec_fping
66
+ cmd = "#{@fping_path} -i #{@fping_interval*1000} -T #{@fping_timeout} -c #{@fping_count} #{@target} -s"
67
+
68
+ cmd_results = run_cmd(cmd)
69
+
70
+ round_trip_times = Hash.new(nil)
71
+
72
+ cmd_results[1].split("\n").each do |line|
73
+ if /([^\s]*) ms \(min round trip time\)/=~ line
74
+ round_trip_times[:min] = $1.to_f
75
+ end
76
+ if /([^\s]*) ms \(avg round trip time\)/=~ line
77
+ round_trip_times[:avg]= $1.to_f
78
+ end
79
+ if /([^\s]*) ms \(max round trip time\)/=~ line
80
+ round_trip_times[:max] = $1.to_f
81
+ end
82
+ end
83
+
84
+ round_trip_times
85
+ end
86
+
87
+
88
+ def exec_curl
89
+ cmd = "#{@curl_path} #{@target} -w \%\{time_total\} -m #{@curl_timeout}"
90
+
91
+ result_times = []
92
+
93
+ @curl_count.times do
94
+ cmd_results = run_cmd(cmd)
95
+ result_times << cmd_results[0].split("\n").last.to_f * 1000
96
+ sleep @curl_interval
97
+ end
98
+
99
+ results = {}
100
+
101
+ results[:max] = result_times.max
102
+ results[:min] = result_times.min
103
+ results[:avg] = result_times.inject(0.0){|r,i| r+=i }/result_times.size
104
+
105
+ results
106
+ end
107
+
108
+ private
109
+
110
+ def init_eventmachine
111
+ unless EM.reactor_running?
112
+ EM.epoll; EM.kqueue
113
+ EM.error_handler do |ex|
114
+ $log.fatal("Eventmachine problem")
115
+ $log.fatal("#{ex}, tracelog : \n#{ex.backtrace.join("\n")}")
116
+ end
117
+ end
118
+ end
119
+
120
+ def run_cmd(cmd)
121
+ require "open3"
122
+ begin
123
+ results = Open3.capture3(cmd)
124
+ return results
125
+ rescue =>e
126
+ $log.warn "[SystemCommond]E:" + e
127
+ return false
128
+ end
129
+ end
130
+
131
+ end
132
+ end
133
+
@@ -0,0 +1,49 @@
1
+ require 'test/unit'
2
+ require 'test_helper'
3
+ require 'lib/fluent/plugin/in_network_probe.rb'
4
+ require 'pp'
5
+
6
+
7
+ class NetworkProbeCurlInputTest < Test::Unit::TestCase
8
+ def setup
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ CONFIG = %[
13
+ probe_type curl
14
+ target google.co.jp
15
+ ]
16
+
17
+ def create_driver(conf=CONFIG)
18
+ Fluent::Test::InputTestDriver.new(Fluent::NetworkProbeInput).configure(conf)
19
+ end
20
+
21
+ def test_configure
22
+ d = create_driver
23
+ assert_equal 'curl', d.instance.probe_type
24
+ assert_equal 'google.co.jp', d.instance.target
25
+ end
26
+
27
+ def test_curl
28
+ d = create_driver
29
+
30
+ pp d.instance.exec_curl
31
+ end
32
+
33
+
34
+ def test_get_events
35
+ d = create_driver
36
+
37
+ # d.instance.before_events = before_events_stub
38
+ end
39
+
40
+ def test_get_usage
41
+ d = create_driver
42
+
43
+ # d.instance.get_usages
44
+ end
45
+
46
+ end
47
+
48
+
49
+
@@ -0,0 +1,53 @@
1
+ require 'test/unit'
2
+ require 'test_helper'
3
+ require 'lib/fluent/plugin/in_network_probe.rb'
4
+ require 'pp'
5
+
6
+
7
+ class NetworkProbeFpingInputTest < Test::Unit::TestCase
8
+ def setup
9
+ Fluent::Test.setup
10
+ end
11
+
12
+ CONFIG = %[
13
+ probe_type fping
14
+ target localhost
15
+ ]
16
+
17
+
18
+ def create_driver(conf=CONFIG)
19
+ Fluent::Test::InputTestDriver.new(Fluent::NetworkProbeInput).configure(conf)
20
+ end
21
+
22
+ def test_configure
23
+ d = create_driver
24
+ assert_equal 'localhost', d.instance.target
25
+ assert_equal 'fping', d.instance.probe_type
26
+ end
27
+
28
+ def test_fping
29
+ d = create_driver
30
+
31
+ d.instance.exec_fping
32
+ end
33
+
34
+
35
+ def test_get_events
36
+ d = create_driver
37
+
38
+ # d.instance.before_events = before_events_stub
39
+ end
40
+
41
+ def test_get_usage
42
+ d = create_driver
43
+
44
+ # d.instance.get_usages
45
+ end
46
+
47
+ end
48
+
49
+
50
+
51
+
52
+
53
+
@@ -0,0 +1,28 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ begin
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts "Run `bundle install` to install missing gems"
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'test/unit'
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ require 'fluent/test'
17
+
18
+ unless ENV.has_key?('VERBOSE')
19
+ nulllogger = Object.new
20
+ nulllogger.instance_eval {|obj|
21
+ def method_missing(method, *args)
22
+ # pass
23
+ end
24
+ }
25
+ $log = nulllogger
26
+ end
27
+
28
+
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-network-probe
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Yuichi UEMURA
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fluentd
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.7
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.7
27
+ - !ruby/object:Gem::Dependency
28
+ name: eventmachine
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Fluentd input plugin to probe network latency and keepalive, similar
56
+ to smokeping
57
+ email:
58
+ - yuichi.u@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - Gemfile.lock
66
+ - README.textile
67
+ - Rakefile
68
+ - VERSION
69
+ - fluent-plugin-network-probe.gemspec
70
+ - lib/fluent/plugin/in_network_probe.rb
71
+ - test/plugin/in_network_probe_curl.rb
72
+ - test/plugin/in_network_probe_fping.rb
73
+ - test/test_helper.rb
74
+ homepage: https://github.com/u-ichi/fluent-plugin-network-probe
75
+ licenses: []
76
+ metadata: {}
77
+ post_install_message:
78
+ rdoc_options: []
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ requirements: []
92
+ rubyforge_project:
93
+ rubygems_version: 2.0.3
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Fluentd input plugin to probe network latency and keepalive, similar to smokeping
97
+ test_files:
98
+ - test/plugin/in_network_probe_curl.rb
99
+ - test/plugin/in_network_probe_fping.rb
100
+ - test/test_helper.rb