fluent-plugin-latency 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: e04db26bee1aa442cf3d1d2fcaa0277a48f3c17f
4
+ data.tar.gz: 55a9002207cefe088c92b5f06eff1101ede0a087
5
+ SHA512:
6
+ metadata.gz: 17187e3431a42083afa94b8fc5f2d5896dd4a981b49edbbd5208d2261be0cf12d3af27af49a1c03332a234b7f88bf8b441dede5eb21051f746e8dcbf42bbe3ff
7
+ data.tar.gz: 7c5e846831a25a9a21ed3917dca9848bfaa5425f283b86431b5a4fc50d8e0e2b9201221243bc2c9c5002130c5b01332e0b9aab08530803f36b5892895c46c702
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /*.gem
2
+ ~*
3
+ #*
4
+ *~
5
+ .bundle
6
+ Gemfile.lock
7
+ .rbenv-version
8
+ vendor
9
+ doc/*
10
+ tmp/*
11
+ coverage
12
+ .yardoc
13
+ pkg/
14
+ .ruby-version
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.0.1 (2014/04/24)
2
+
3
+ First release
4
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+ gem 'fluent-plugin-flowcounter' # for examples
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Naotoshi SEO
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,94 @@
1
+ # fluent-plugin-latency
2
+
3
+ [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-latency.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-latency)
4
+
5
+ Fluentd plugin to measure latency until receiving the messages.
6
+
7
+ ## What Is It For?
8
+
9
+ This plugin is to investigate the network latency, in addition, the blocking situation of input plugins.
10
+
11
+ In the Fluentd mechanism, input plugins usually blocks and will not receive a new data until the previous data processing finishes.
12
+
13
+ By seeing the latency, you can easily find how long the blocking situation is occuring.
14
+
15
+ ## How It Works
16
+
17
+ Fluentd messages include the time attribute which expresses the time of when the message is created, or when it is written in application logs.
18
+
19
+ This plugin takes the difference between the current time and the time attribute to obtain the latency.
20
+
21
+ ## Installation
22
+
23
+ Use RubyGems:
24
+
25
+ gem install fluent-plugin-latency
26
+
27
+ ## Configuration
28
+
29
+ Following example measures the max and average latency until receiving messages.
30
+ Note that this example uses [fluent-plugin-reemit](https://github.com/sonots/fluent-plugin-reemit) to capture all messages once, measure latencies, and then re-emit.
31
+
32
+ ```apache
33
+ <source>
34
+ type forward
35
+ port 24224
36
+ </source>
37
+
38
+ # Latency plugin output comes here
39
+ <match latency>
40
+ type stdout
41
+ </match>
42
+
43
+ # All messages come here once. Measure latencies and re-emit
44
+ <match **>
45
+ type copy
46
+ <store>
47
+ type latency
48
+ tag latency
49
+ interval 60
50
+ </store>
51
+ <store>
52
+ type reemit
53
+ </store>
54
+ </match>
55
+
56
+ # Whatever you want to do
57
+ <match **>
58
+ type stdout
59
+ </match>
60
+ ```
61
+
62
+ Output will be like
63
+
64
+ ```
65
+ latency: {"max":1.011,"avg":0.002","num":10}
66
+ ```
67
+
68
+ where `max` and `avg` are the maximum and average latency, and `num` is the number of messages.
69
+
70
+ ## Option Parameters
71
+
72
+ * interval
73
+
74
+ The time interval to emit measurement results
75
+
76
+ * tag
77
+
78
+ The output tag name. Default is `latency`
79
+
80
+ ## ChangeLog
81
+
82
+ See [CHANGELOG.md](CHANGELOG.md) for details.
83
+
84
+ ## Contributing
85
+
86
+ 1. Fork it
87
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
88
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
89
+ 4. Push to the branch (`git push origin my-new-feature`)
90
+ 5. Create new [Pull Request](../../pull/new/master)
91
+
92
+ ## Copyright
93
+
94
+ Copyright (c) 2014 Naotoshi Seo. See [LICENSE](LICENSE) for details.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ require "bundler/gem_tasks"
3
+
4
+ require 'rspec/core'
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec) do |spec|
7
+ spec.pattern = FileList['spec/**/*_spec.rb']
8
+ end
9
+ task :default => :spec
10
+
11
+ desc 'Open an irb session preloaded with the gem library'
12
+ task :console do
13
+ sh 'irb -rubygems -I lib'
14
+ end
15
+ task :c => :console
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-latency"
6
+ gem.version = "0.0.1"
7
+ gem.authors = ["Naotoshi Seo"]
8
+ gem.email = "sonots@gmail.com"
9
+ gem.homepage = "https://github.com/sonots/fluent-plugin-latency"
10
+ gem.description = "Fluentd plugin to measure latency until receiving the messages"
11
+ gem.summary = gem.description
12
+ gem.licenses = ["MIT"]
13
+ gem.has_rdoc = false
14
+
15
+ gem.files = `git ls-files`.split("\n")
16
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency "fluentd"
21
+ gem.add_development_dependency "rake"
22
+ gem.add_development_dependency "rspec"
23
+ gem.add_development_dependency "pry"
24
+ gem.add_development_dependency "pry-nav"
25
+ gem.add_development_dependency "timecop"
26
+ end
@@ -0,0 +1,63 @@
1
+ module Fluent
2
+ class LatencyOutput < MultiOutput
3
+ Plugin.register_output('latency', self)
4
+
5
+ # To support log_level option implemented by Fluentd v0.10.43
6
+ unless method_defined?(:log)
7
+ define_method("log") { $log }
8
+ end
9
+
10
+ config_param :tag, :string, :default => 'latency'
11
+ config_param :interval, :time, :default => 60
12
+
13
+ attr_reader :latency # for test
14
+
15
+ def initialize
16
+ super
17
+ @latency = []
18
+ end
19
+
20
+ def configure(conf)
21
+ super
22
+ end
23
+
24
+ def emit(tag, es, chain)
25
+ current = Time.now.to_f
26
+ es.each do |time, record|
27
+ @latency << (current - time)
28
+ end
29
+ chain.next
30
+ end
31
+
32
+ def start
33
+ super
34
+ @thread = Thread.new(&method(:run))
35
+ end
36
+
37
+ def shutdown
38
+ super
39
+ @thread.terminate
40
+ @thread.join
41
+ end
42
+
43
+ def run
44
+ @last_checked ||= Engine.now
45
+ while (sleep 0.5)
46
+ now = Engine.now
47
+ if now - @last_checked >= @interval
48
+ flush_emit
49
+ @last_checked = now
50
+ end
51
+ end
52
+ end
53
+
54
+ def flush_emit
55
+ latency, @latency = @latency, []
56
+ num = latency.size
57
+ max = num == 0 ? 0 : latency.max
58
+ avg = num == 0 ? 0 : latency.map(&:to_f).inject(:+) / num.to_f
59
+ message = {"max" => max, "avg" => avg, "num" => num}
60
+ Engine.emit(@tag, Engine.now, message)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: UTF-8
2
+ require_relative 'spec_helper'
3
+
4
+ describe Fluent::LatencyOutput do
5
+ before { Fluent::Test.setup }
6
+ let(:config) { %[] }
7
+ let(:tag) { 'tag' }
8
+ let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::LatencyOutput, tag).configure(config) }
9
+
10
+ describe 'test configure' do
11
+ subject { driver.instance }
12
+
13
+ context "check default" do
14
+ let(:config) { %[] }
15
+ its(:tag) { should == 'latency' }
16
+ its(:interval) { should == 60 }
17
+ end
18
+
19
+ context "check config" do
20
+ let(:config) { %[tag tag\ninterval 120]}
21
+ its(:tag) { should == 'tag' }
22
+ its(:interval) { should == 120 }
23
+ end
24
+ end
25
+
26
+ describe 'test emit' do
27
+ let(:emit_time) { Time.utc(1,1,1,1,1,2010,nil,nil,nil,nil).to_i }
28
+ let(:current_time) { Time.utc(2,1,1,1,1,2010,nil,nil,nil,nil).to_i }
29
+ let(:message) { "INFO GET /ping" }
30
+ let(:expected) { {"max" => 1.0, "avg" => 1.0, "num" => 1} }
31
+ before {
32
+ Timecop.freeze(Time.at(current_time))
33
+ Fluent::Engine.should_receive(:emit).with("latency", current_time, expected)
34
+ }
35
+ after { Timecop.return }
36
+ it {
37
+ driver.run { driver.emit({'message' => message}, emit_time) }
38
+ driver.instance.flush_emit
39
+ }
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup(:default, :test)
5
+ Bundler.require(:default, :test)
6
+
7
+ require 'fluent/test'
8
+ require 'rspec'
9
+ require 'pry'
10
+ require 'timecop'
11
+
12
+ $TESTING=true
13
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
14
+ require 'fluent/plugin/out_latency'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-latency
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-24 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'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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-nav
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
+ - !ruby/object:Gem::Dependency
84
+ name: timecop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Fluentd plugin to measure latency until receiving the messages
98
+ email: sonots@gmail.com
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - .gitignore
104
+ - .rspec
105
+ - .travis.yml
106
+ - CHANGELOG.md
107
+ - Gemfile
108
+ - LICENSE
109
+ - README.md
110
+ - Rakefile
111
+ - fluent-plugin-latency.gemspec
112
+ - lib/fluent/plugin/out_latency.rb
113
+ - spec/out_latency.rb
114
+ - spec/spec_helper.rb
115
+ homepage: https://github.com/sonots/fluent-plugin-latency
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - '>='
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.0.3
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Fluentd plugin to measure latency until receiving the messages
139
+ test_files:
140
+ - spec/out_latency.rb
141
+ - spec/spec_helper.rb