fluent-plugin-flowcounter-simple 0.0.1
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 +7 -0
- data/.gitignore +14 -0
- data/.travis.yml +6 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +42 -0
- data/Rakefile +11 -0
- data/fluent-plugin-flowcounter-simple.gemspec +21 -0
- data/lib/fluent/plugin/out_flowcounter_simple.rb +93 -0
- data/test/helper.rb +18 -0
- data/test/plugin/test_out_flowcounter_simple.rb +67 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5216d3378426ae3848440710ccbaef547072e6ae
|
4
|
+
data.tar.gz: 9457e194d2c09ff32aa0a78770671fb12c89c8a3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 887e11504a1bf669daa5a93fc4973afdef066737453effc6b3144aaea3d15fbc8f63bff41d16aeb820a724302b870b5cb5636716afb0ffaa7c3027520fa13cfd
|
7
|
+
data.tar.gz: ff478a165066e0f53835a71f0b5cc706b3401c22b3c58c39bc090ab11effee09e7d49c1a48accc9358894121b74ffa8c5c44969a551922d093efb480cbfbed21
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
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,42 @@
|
|
1
|
+
# fluent-plugin-flowcounter-simple [](http://travis-ci.org/sonots/fluent-plugin-flowcounter-simple)
|
2
|
+
|
3
|
+
Simple Fluentd Plugin to count number of messages and outputs to log
|
4
|
+
|
5
|
+
## Configuration
|
6
|
+
|
7
|
+
<match foo.bar.**>
|
8
|
+
type flowcounter_simple
|
9
|
+
unit second
|
10
|
+
</source>
|
11
|
+
|
12
|
+
This plugin does not emit, just writes into the log file as
|
13
|
+
|
14
|
+
plugin:out_flowcounter_simple count:30 indicator:num unit:second
|
15
|
+
|
16
|
+
## Parameters
|
17
|
+
|
18
|
+
- unit
|
19
|
+
|
20
|
+
One of second/minute/hour/day. Default: minute
|
21
|
+
|
22
|
+
- indicator
|
23
|
+
|
24
|
+
One of num/byte. Default: num
|
25
|
+
|
26
|
+
## Relatives
|
27
|
+
|
28
|
+
There is a [fluent-plugin-flowcounter](https://github.com/tagomoris/fluent-plugin-flowcounter),
|
29
|
+
but I needed a very very simple plugin to use for performance evaluation.
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create new [Pull Request](../../pull/new/master)
|
38
|
+
|
39
|
+
## Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2013 Naotoshi Seo. See [LICENSE.txt](LICENSE.txt) for details.
|
42
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = "fluent-plugin-flowcounter-simple"
|
4
|
+
gem.version = "0.0.1"
|
5
|
+
gem.authors = ["Naotoshi Seo"]
|
6
|
+
gem.email = ["sonots@gmail.com"]
|
7
|
+
gem.summary = %q{Simple Fluentd Plugin to count number of messages and outputs to log}
|
8
|
+
gem.description = %q{Simple Fluentd Plugin to count number of messages and outputs to log}
|
9
|
+
gem.homepage = "https://github.com/sonots/fluent-plugin-flowcounter-simple"
|
10
|
+
gem.license = "MIT"
|
11
|
+
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
|
17
|
+
gem.add_runtime_dependency "fluentd"
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_development_dependency "pry"
|
20
|
+
gem.add_development_dependency "pry-nav"
|
21
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
class Fluent::FlowCounterSimpleOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('flowcounter_simple', self)
|
3
|
+
|
4
|
+
config_param :indicator, :string, :default => 'num'
|
5
|
+
config_param :unit, :string, :default => 'second'
|
6
|
+
|
7
|
+
attr_accessor :last_checked
|
8
|
+
|
9
|
+
def configure(conf)
|
10
|
+
super
|
11
|
+
|
12
|
+
@indicator_proc =
|
13
|
+
case @indicator
|
14
|
+
when 'num' then Proc.new {|record| 1 }
|
15
|
+
when 'byte' then Proc.new {|record| record.to_msgpack.size }
|
16
|
+
else
|
17
|
+
raise Fluent::ConfigError, "flowcounter-simple count allows num/byte"
|
18
|
+
end
|
19
|
+
@unit =
|
20
|
+
case @unit
|
21
|
+
when 'second' then :second
|
22
|
+
when 'minute' then :minute
|
23
|
+
when 'hour' then :hour
|
24
|
+
when 'day' then :day
|
25
|
+
else
|
26
|
+
raise Fluent::ConfigError, "flowcounter-simple unit allows second/minute/hour/day"
|
27
|
+
end
|
28
|
+
@tick =
|
29
|
+
case @unit
|
30
|
+
when :second then 1
|
31
|
+
when :minute then 60
|
32
|
+
when :hour then 3600
|
33
|
+
when :day then 86400
|
34
|
+
else
|
35
|
+
raise RuntimeError, "@unit must be one of second/minute/hour/day"
|
36
|
+
end
|
37
|
+
|
38
|
+
@count = 0
|
39
|
+
@mutex = Mutex.new
|
40
|
+
end
|
41
|
+
|
42
|
+
def start
|
43
|
+
super
|
44
|
+
start_watch
|
45
|
+
end
|
46
|
+
|
47
|
+
def shutdown
|
48
|
+
super
|
49
|
+
@watcher.terminate
|
50
|
+
@watcher.join
|
51
|
+
end
|
52
|
+
|
53
|
+
def countup(count)
|
54
|
+
@mutex.synchronize {
|
55
|
+
@count = (@count || 0) + count
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def flush_emit(step)
|
60
|
+
count, @count = @count, 0
|
61
|
+
if count > 0
|
62
|
+
$log.info "plugin:out_flowcounter_simple\tcount:#{count}\tindicator:#{@indicator}\tunit:#{@unit}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def start_watch
|
67
|
+
# for internal, or tests only
|
68
|
+
@watcher = Thread.new(&method(:watch))
|
69
|
+
end
|
70
|
+
|
71
|
+
def watch
|
72
|
+
# instance variable, and public accessable, for test
|
73
|
+
@last_checked = Fluent::Engine.now
|
74
|
+
while true
|
75
|
+
sleep 0.1
|
76
|
+
if Fluent::Engine.now - @last_checked >= @tick
|
77
|
+
now = Fluent::Engine.now
|
78
|
+
flush_emit(now - @last_checked)
|
79
|
+
@last_checked = now
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def emit(tag, es, chain)
|
85
|
+
count = 0
|
86
|
+
es.each {|time,record|
|
87
|
+
count += @indicator_proc.call(record)
|
88
|
+
}
|
89
|
+
countup(count)
|
90
|
+
|
91
|
+
chain.next
|
92
|
+
end
|
93
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
13
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
14
|
+
require 'fluent/test'
|
15
|
+
require 'fluent/plugin/out_flowcounter_simple'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class FlowCounterSimpleOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG = %[
|
9
|
+
unit second
|
10
|
+
]
|
11
|
+
|
12
|
+
def create_driver(conf=CONFIG,tag='test')
|
13
|
+
Fluent::Test::OutputTestDriver.new(Fluent::FlowCounterSimpleOutput, tag).configure(conf)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_configure
|
17
|
+
assert_nothing_raised {
|
18
|
+
d = create_driver('')
|
19
|
+
}
|
20
|
+
assert_nothing_raised {
|
21
|
+
d = create_driver(CONFIG)
|
22
|
+
}
|
23
|
+
assert_nothing_raised {
|
24
|
+
d = create_driver(CONFIG + %[indicator num])
|
25
|
+
}
|
26
|
+
assert_nothing_raised {
|
27
|
+
d = create_driver(CONFIG + %[indicator byte])
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_num
|
32
|
+
d1 = create_driver(CONFIG, 'test.tag1')
|
33
|
+
d1.run do
|
34
|
+
10.times do
|
35
|
+
d1.emit({'message'=> 'a' * 100})
|
36
|
+
d1.emit({'message'=> 'b' * 100})
|
37
|
+
d1.emit({'message'=> 'c' * 100})
|
38
|
+
end
|
39
|
+
end
|
40
|
+
log = capture_log { d1.instance.flush_emit(60) }
|
41
|
+
assert( log.include?("count:30"), log )
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_byte
|
45
|
+
d1 = create_driver(CONFIG + %[indicator byte], 'test.tag1')
|
46
|
+
d1.run do
|
47
|
+
10.times do
|
48
|
+
d1.emit({'message'=> 'a' * 100})
|
49
|
+
d1.emit({'message'=> 'b' * 100})
|
50
|
+
d1.emit({'message'=> 'c' * 100})
|
51
|
+
end
|
52
|
+
end
|
53
|
+
log = capture_log { d1.instance.flush_emit(60) }
|
54
|
+
assert( log.include?("count:3360"), log )
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def capture_log
|
60
|
+
tmp = $log.out
|
61
|
+
$log.out = StringIO.new
|
62
|
+
yield
|
63
|
+
return $log.out.string
|
64
|
+
ensure
|
65
|
+
$log.out = tmp
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-flowcounter-simple
|
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: 2013-11-27 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: pry
|
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-nav
|
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
|
+
description: Simple Fluentd Plugin to count number of messages and outputs to log
|
70
|
+
email:
|
71
|
+
- sonots@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- .travis.yml
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- fluent-plugin-flowcounter-simple.gemspec
|
83
|
+
- lib/fluent/plugin/out_flowcounter_simple.rb
|
84
|
+
- test/helper.rb
|
85
|
+
- test/plugin/test_out_flowcounter_simple.rb
|
86
|
+
homepage: https://github.com/sonots/fluent-plugin-flowcounter-simple
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.0.3
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Simple Fluentd Plugin to count number of messages and outputs to log
|
110
|
+
test_files:
|
111
|
+
- test/helper.rb
|
112
|
+
- test/plugin/test_out_flowcounter_simple.rb
|