fluent-plugin-elapsed-time 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6720e8ded7541bd64fcf697c652f26dc8698d06
4
+ data.tar.gz: b9fc406ba89a260a898d2f0eebbae70f0494f553
5
+ SHA512:
6
+ metadata.gz: 6b0eb1286b7aa683a562f9b9fb61b78176453543dc1306fe40823cde5dcea4bcdff52239059782dd5e4ad3d9a375640660a0f81254bdd842a789a565c37fddb0
7
+ data.tar.gz: df7c63be74f4ea39658f73eb2cab8035ce3b26851b2dea9adf357fd0b7575d2a3a17ed3fc2bb33647af5b381bed749a19e780c14079ca2382cc8f8f9b226ed4e
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,10 @@
1
+ ## 0.0.2 (2014/01/23)
2
+
3
+ Changes:
4
+
5
+ * Trivial change to output record keys from symbols to strings
6
+
7
+ ## 0.0.1 (2014/01/23)
8
+
9
+ First release
10
+
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,76 @@
1
+ # fluent-plugin-elapsed-time
2
+
3
+ [![Build Status](https://secure.travis-ci.org/sonots/fluent-plugin-elapsed-time.png?branch=master)](http://travis-ci.org/sonots/fluent-plugin-elapsed-time)
4
+
5
+ Fluentd plugin to measure elapsed time to process messages
6
+
7
+ ## Installation
8
+
9
+ Use RubyGems:
10
+
11
+ gem install fluent-plugin-elapsed-time
12
+
13
+ ## Configuration
14
+
15
+ Example:
16
+
17
+ Following example measures the max and average time taken to process [fluent-plugin-grep](https://github.com/sonots/fluent-plugin-grep) => [fluent-plugin-parser](https://github.com/tagomoris/fluent-plugin-parser) => out_stdout chain in messages. Please notice that this plugin measures the total processing time until match chain finishes.
18
+
19
+ ```apache
20
+ <match **>
21
+ type elapsed_time
22
+ tag elapsed
23
+ interval 60
24
+ <store>
25
+ type grep
26
+ exclude foobar
27
+ add_tag_prefix greped
28
+ </store>
29
+ </match>
30
+
31
+ <match greped.**>
32
+ type parse
33
+ format ltsv
34
+ key_name message
35
+ remove_prefix greped
36
+ add_prefix parsed
37
+ </match>
38
+
39
+ <match parsed.**>
40
+ type stdout
41
+ </match>
42
+
43
+ <match elapsed>
44
+ type stdout
45
+ </match>
46
+ ```
47
+
48
+ ## Option Parameters
49
+
50
+ * tag
51
+
52
+ The output tag name. Default is `elapsed`
53
+
54
+ * interval
55
+
56
+ The time interval to emit measurement results
57
+
58
+ * each
59
+
60
+ Measure time for each `message` or `es` (event stream). Please notice that the event stream (would be a msgpack) will be unpacked if `message` is specified, which would cause performance degradation. Default is `es`.
61
+
62
+ ## ChangeLog
63
+
64
+ See [CHANGELOG.md](CHANGELOG.md) for details.
65
+
66
+ ## Contributing
67
+
68
+ 1. Fork it
69
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
70
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
71
+ 4. Push to the branch (`git push origin my-new-feature`)
72
+ 5. Create new [Pull Request](../../pull/new/master)
73
+
74
+ ## Copyright
75
+
76
+ 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,25 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.name = "fluent-plugin-elapsed-time"
6
+ gem.version = "0.0.2"
7
+ gem.authors = ["Naotoshi Seo"]
8
+ gem.email = "sonots@gmail.com"
9
+ gem.homepage = "https://github.com/sonots/fluent-plugin-elapsed-time"
10
+ gem.description = "Fluentd plugin to measure elapsed time to process 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", "~> 0.10.17"
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
+ end
@@ -0,0 +1,105 @@
1
+ module Fluent
2
+ class ElapsedTimeOutput < MultiOutput
3
+ Plugin.register_output('elapsed_time', self)
4
+
5
+ config_param :tag, :string, :default => 'elapsed'
6
+ config_param :interval, :time, :default => 60
7
+ config_param :each, :default => :es do |val|
8
+ case val.downcase
9
+ when 'es'
10
+ :es
11
+ when 'message'
12
+ :message
13
+ else
14
+ raise ConfigError, "out_elapsed_time: each should be 'es' or 'message'"
15
+ end
16
+ end
17
+
18
+ def initialize
19
+ super
20
+ @outputs = []
21
+ @elapsed = []
22
+ end
23
+
24
+ attr_reader :outputs, :elapsed
25
+
26
+ def configure(conf)
27
+ super
28
+ conf.elements.select {|e|
29
+ e.name == 'store'
30
+ }.each {|e|
31
+ type = e['type']
32
+ unless type
33
+ raise ConfigError, "Missing 'type' parameter on <store> directive"
34
+ end
35
+ $log.debug "adding store type=#{type.dump}"
36
+
37
+ output = Plugin.new_output(type)
38
+ output.configure(e)
39
+ @outputs << output
40
+ }
41
+
42
+ @emit_proc =
43
+ if @each == :message
44
+ chain = NullOutputChain.instance
45
+ Proc.new {|tag, es|
46
+ start = Time.now
47
+ es.each do |time, record|
48
+ @outputs.each {|output| output.emit(tag, OneEventStream.new(time, record), chain) }
49
+ finish = Time.now
50
+ @elapsed << (finish - start).to_f
51
+ start = finish
52
+ end
53
+ }
54
+ else
55
+ chain = NullOutputChain.instance
56
+ Proc.new {|tag, es|
57
+ t = Time.now
58
+ @outputs.each {|output| output.emit(tag, es, chain) }
59
+ @elapsed << (Time.now - t).to_f
60
+ }
61
+ end
62
+ end
63
+
64
+ def start
65
+ @outputs.each {|o|
66
+ o.start
67
+ }
68
+ @thread = Thread.new(&method(:run))
69
+ end
70
+
71
+ def shutdown
72
+ @outputs.each {|o|
73
+ o.shutdown
74
+ }
75
+ @thread.terminate
76
+ @thread.join
77
+ end
78
+
79
+ def run
80
+ @last_checked ||= Engine.now
81
+ while (sleep 0.1)
82
+ now = Engine.now
83
+ if now - @last_checked >= @interval
84
+ flush_emit
85
+ @last_checked = now
86
+ end
87
+ end
88
+ end
89
+
90
+ def flush_emit
91
+ elapsed, @elapsed = @elapsed, []
92
+ unless elapsed.empty?
93
+ max = elapsed.max
94
+ num = elapsed.size
95
+ avg = elapsed.map(&:to_f).inject(:+) / num.to_f
96
+ Engine.emit(@tag, Engine.now, {"max" => max, "avg" => avg, "num" => num})
97
+ end
98
+ end
99
+
100
+ def emit(tag, es, chain)
101
+ @emit_proc.call(tag, es)
102
+ chain.next
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,90 @@
1
+ # encoding: UTF-8
2
+ require_relative 'spec_helper'
3
+
4
+ class Fluent::Test::OutputTestDriver
5
+ def emit_with_tag(record, time=Time.now, tag = nil)
6
+ @tag = tag if tag
7
+ emit(record, time)
8
+ end
9
+ end
10
+
11
+ class Hash
12
+ def delete!(key)
13
+ self.tap {|h| h.delete(key) }
14
+ end
15
+ end
16
+
17
+ describe Fluent::ElapsedTimeOutput do
18
+ before { Fluent::Test.setup }
19
+ CONFIG = %[
20
+ tag tag
21
+ interval 120
22
+ each message
23
+ <store>
24
+ type stdout
25
+ </store>
26
+ ]
27
+ let(:tag) { 'syslog.host1' }
28
+ let(:driver) { Fluent::Test::OutputTestDriver.new(Fluent::ElapsedTimeOutput, tag).configure(config) }
29
+
30
+ describe 'test configure' do
31
+ describe 'bad configuration' do
32
+ context 'invalid each' do
33
+ let(:config) { CONFIG + %[each foobar] }
34
+ it { expect { driver }.to raise_error(Fluent::ConfigError) }
35
+ end
36
+ end
37
+
38
+ describe 'good configuration' do
39
+ subject { driver.instance }
40
+
41
+ context "check default" do
42
+ let(:config) { %[] }
43
+ its(:tag) { should == 'elapsed' }
44
+ its(:interval) { should == 60 }
45
+ its(:each) { should == :es }
46
+ end
47
+
48
+ context "check config" do
49
+ let(:config) { CONFIG }
50
+ its(:tag) { should == 'tag' }
51
+ its(:interval) { should == 120 }
52
+ its(:each) { should == :message }
53
+ end
54
+ end
55
+ end
56
+
57
+ describe 'test emit' do
58
+ let(:time) { Time.now.to_i }
59
+ let(:messages) do
60
+ [
61
+ "2013/01/13T07:02:11.124202 INFO GET /ping",
62
+ "2013/01/13T07:02:13.232645 WARN POST /auth",
63
+ "2013/01/13T07:02:21.542145 WARN GET /favicon.ico",
64
+ "2013/01/13T07:02:43.632145 WARN POST /login",
65
+ ]
66
+ end
67
+
68
+ context 'each message' do
69
+ let(:config) { CONFIG + %[each message]}
70
+ before do
71
+ Fluent::Engine.stub(:now).and_return(time)
72
+ end
73
+ it {
74
+ driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
75
+ driver.instance.elapsed.size.should == 4
76
+ }
77
+ end
78
+
79
+ context 'each es' do
80
+ let(:config) { CONFIG + %[each es]}
81
+ before do
82
+ Fluent::Engine.stub(:now).and_return(time)
83
+ end
84
+ it {
85
+ driver.run { messages.each {|message| driver.emit({'message' => message}, time) } }
86
+ driver.instance.elapsed.size.should == 4
87
+ }
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,13 @@
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
+
11
+ $TESTING=true
12
+ $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
13
+ require 'fluent/plugin/out_elapsed_time'
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fluent-plugin-elapsed-time
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Naotoshi Seo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-23 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.17
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.17
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
+ description: Fluentd plugin to measure elapsed time to process messages
84
+ email: sonots@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .rspec
91
+ - .travis.yml
92
+ - CHANGELOG.md
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - fluent-plugin-elapsed-time.gemspec
98
+ - lib/fluent/plugin/out_elapsed_time.rb
99
+ - spec/out_elapsed_time_spec.rb
100
+ - spec/spec_helper.rb
101
+ homepage: https://github.com/sonots/fluent-plugin-elapsed-time
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: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.0.3
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Fluentd plugin to measure elapsed time to process messages
125
+ test_files:
126
+ - spec/out_elapsed_time_spec.rb
127
+ - spec/spec_helper.rb