fluent-plugin-combiner 0.0.1 → 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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MjI2MTFmNDQxOTgxNjNjZDg2ZTZmNGNiMzljYzhjNTZlNDU2MmExOQ==
4
+ OTQ1YTU4ODMzYTk2ZjQ4OTAyMjFhNWU4NTIwY2U2YmU2ODI5YzM0ZA==
5
5
  data.tar.gz: !binary |-
6
- ZGYzZWU1NjExZjAyYTlhZTIyNzVlZWVmOWZkZjU1NmFhNDlkYWY3Mg==
6
+ NDc1M2M4ZDQ1M2M1M2I3OTZjMzBlMTg4MmIxY2ZiZjY2YzM5ODEyNA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGU5NjM4N2NhZjBmNTdiODFhYzhjZjgxZmRjY2E4YWY3YmE5YzNkMzVmYjc1
10
- NjhjMjJkOWQ2MTc2Yzc1OTRjY2NkZDQxYzdhMWQzMmE0N2ZhMjIwNzdkNTRk
11
- YjI0NzZkNDhhNDdhYTcwY2Q2MWMxMTIwYmE2ZDNmNGI1YjE3Mjk=
9
+ ZTVmYzZhMTkwZjgyZDYwYTliOGQwOGVjZTAwZjhkOGUyMGQ3YTU2MWMzMWU4
10
+ N2YwMDliYzhmNGU3NjZkMTc4NGUwODMyNjFhYmNkMzcxMDY2ZmExMDIzZTUy
11
+ NzVlNzA5ODllYjM5NzliNDkyYzQ0NjQyODcxYzM2OWQ2YWM5Nzg=
12
12
  data.tar.gz: !binary |-
13
- MzM2ZjQ5ZWY5ZGViMjAxY2M0NGY3ZjM2ZWYwOGIzY2U1OTE1ZTk0ZTMyYmM1
14
- MmVkNGQxMGQ5YjEzYThkNDBhOTBmNDRjMzMwOWM2MjBhOWQyODc4YTc2OTE5
15
- YzQwNmY4MjUzY2E5OTI0MGJlNDYyMTdjNTU3ZGMwMGFhOWJkYTM=
13
+ ZGYxYWNjOTE5N2U3ZWU1MjY0M2QwYmYyZTk0NjVmNWQwNDJmZTZmNmQ0MDg4
14
+ MTI0NzNlNzA1MTA0MmY5NDI1OTIwY2JlNGUzMTE4NGRhODBkODMyNTNiODI2
15
+ ZjhlMDIwMDI5NTdiOWI0NmFhMTAzMDYwYTI0MGRjNjQ4OTk3Mjk=
data/README.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # fluent-plugin-combiner
2
2
 
3
+ Fluentd plugin to count message keys, and make histogram.
4
+
5
+ ```
6
+ $ echo '{"keys":["A", "B", "C", "A"]}' | fluent-cat test.combine.input
7
+ $ echo '{"keys":["A", "B", "D"]}' | fluent-cat test.combine.input
8
+ ```
9
+
10
+ output is
11
+
12
+ ```
13
+ 2013-12-17 01:06:46 +0900 combined.input: {"hist":{"A":3, "B":2, "C":1, "D":1}, "sum":7, "len":4}
14
+ ```
15
+
16
+ ## Configuration
17
+
18
+ ```
19
+ <match test.combine.**>
20
+ type combiner
21
+ count_key keys # input message tag to count
22
+ count_interval 5 # count interval(second)
23
+ tag_prefix combined
24
+ input_tag_remove_prefix test.combine
25
+ </match>
26
+ ```
27
+
28
+ !!`tag` parameter overwrite `tag_prefix` and `input_tag_remove_prefix`
29
+
30
+
3
31
  ## Installation
4
32
 
5
33
  Add this line to your application's Gemfile:
@@ -14,9 +42,6 @@ Or install it yourself as:
14
42
 
15
43
  $ gem install fluent-plugin-combiner
16
44
 
17
- ## Usage
18
-
19
- TODO: Write usage instructions here
20
45
 
21
46
  ## Contributing
22
47
 
@@ -0,0 +1,30 @@
1
+ Benchmark tool for Fluent event collector
2
+ =========================================
3
+
4
+ ## Install
5
+
6
+ # genload.rb depends on fluent gem
7
+ $ gem install fluent
8
+
9
+ ## Usage
10
+
11
+ Usage: genload [options] <tag> <num>
12
+ -p, --port PORT fluent tcp port (default: 24224)
13
+ -h, --host HOST fluent host (default: 127.0.0.1)
14
+ -u, --unix use unix socket instead of tcp
15
+ -P, --path PATH unix socket path (default: /var/run/fluent/fluent.sock)
16
+ -r, --repeat NUM repeat number (default: 1)
17
+ -m, --multi NUM send multiple records at once (default: 1)
18
+ -c, --concurrent NUM number of threads (default: 1)
19
+ -s, --size SIZE size of a record (default: 100)
20
+ -G, --no-packed don't use lazy deserialization optimize
21
+
22
+
23
+ ## Examples
24
+
25
+ # uses "benchmark.buffered" tag and sends 50,000 records
26
+ # -c: uses 10 threads/connections;
27
+ # -m: one message includes 20 record
28
+ # -r: repeats 100 times
29
+ ruby genload.rb benchamrk.buffered 50000 -c 10 -m 20 -r 100
30
+
@@ -0,0 +1,152 @@
1
+ require 'optparse'
2
+ require 'fluent/env'
3
+
4
+ op = OptionParser.new
5
+
6
+ op.banner += " <tag> <num>"
7
+
8
+ port = Fluent::DEFAULT_LISTEN_PORT
9
+ host = '127.0.0.1'
10
+ unix = false
11
+ socket_path = Fluent::DEFAULT_SOCKET_PATH
12
+ send_timeout = 20.0
13
+ repeat = 1
14
+ para = 1
15
+ multi = 1
16
+ record_len = 5
17
+ packed = true
18
+
19
+ config_path = Fluent::DEFAULT_CONFIG_PATH
20
+
21
+ op.on('-p', '--port PORT', "fluent tcp port (default: #{port})", Integer) {|i|
22
+ port = s
23
+ }
24
+
25
+ op.on('-h', '--host HOST', "fluent host (default: #{host})") {|s|
26
+ host = s
27
+ }
28
+
29
+ op.on('-u', '--unix', "use unix socket instead of tcp", TrueClass) {|b|
30
+ unix = b
31
+ }
32
+
33
+ op.on('-P', '--path PATH', "unix socket path (default: #{socket_path})") {|s|
34
+ socket_path = s
35
+ }
36
+
37
+ op.on('-r', '--repeat NUM', "repeat number (default: 1)", Integer) {|i|
38
+ repeat = i
39
+ }
40
+
41
+ op.on('-m', '--multi NUM', "send multiple records at once (default: 1)", Integer) {|i|
42
+ multi = i
43
+ }
44
+
45
+ op.on('-l', '--record_len NUM', "a record to be send have NUM keys (default: 5)", Integer) {|i|
46
+ record_len = i
47
+ }
48
+
49
+ op.on('-c', '--concurrent NUM', "number of threads (default: 1)", Integer) {|i|
50
+ para = i
51
+ }
52
+
53
+ op.on('-G', '--no-packed', "don't use lazy deserialization optimize") {|i|
54
+ packed = false
55
+ }
56
+
57
+ (class<<self;self;end).module_eval do
58
+ define_method(:usage) do |msg|
59
+ puts op.to_s
60
+ puts "error: #{msg}" if msg
61
+ exit 1
62
+ end
63
+ end
64
+
65
+ begin
66
+ op.parse!(ARGV)
67
+
68
+ if ARGV.length != 2
69
+ usage nil
70
+ end
71
+
72
+ tag = ARGV.shift
73
+ num = ARGV.shift.to_i
74
+
75
+ rescue
76
+ usage $!.to_s
77
+ end
78
+
79
+ require 'socket'
80
+ require 'msgpack'
81
+ require 'benchmark'
82
+
83
+ def gen_word(len=nil)
84
+ len = rand(5) + 1 unless len
85
+ rand(36**len).to_s(36)
86
+ end
87
+
88
+ def gen_record(num=5, w_len=nil)
89
+ (1..num).reduce([]) {|ret| ret << gen_word(w_len)}
90
+ end
91
+
92
+
93
+ connector = Proc.new {
94
+ if unix
95
+ sock = UNIXSocket.open(socket_path)
96
+ else
97
+ sock = TCPSocket.new(host, port)
98
+ end
99
+
100
+ opt = [1, send_timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; }
101
+ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt)
102
+
103
+ opt = [send_timeout.to_i, 0].pack('L!L!') # struct timeval
104
+ sock.setsockopt(Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, opt)
105
+
106
+ sock
107
+ }
108
+
109
+ def gen_data(tag, multi=1, r_len=5)
110
+ time = Time.now.to_i
111
+ data = ''
112
+ multi.times do
113
+ record = {"keys"=>gen_record(r_len)}
114
+ [time, record].to_msgpack(data)
115
+ end
116
+ data = [tag, data].to_msgpack
117
+ end
118
+
119
+ size = 0 # sum of data.bytesize
120
+ repeat.times do
121
+ puts "--- #{Time.now}"
122
+ Benchmark.bm do |x|
123
+ start = Time.now
124
+
125
+ lo = num / para / multi
126
+ lo = 1 if lo == 0
127
+
128
+ x.report do
129
+ (1..para).map {
130
+ Thread.new do
131
+ sock = connector.call
132
+ lo.times do
133
+ data = gen_data(tag, multi, record_len)
134
+ size += data.bytesize
135
+ sock.write data
136
+ end
137
+ sock.close
138
+ end
139
+ }.each {|t|
140
+ t.join
141
+ }
142
+ end
143
+
144
+ finish = Time.now
145
+ elapsed = finish - start
146
+
147
+ puts "% 10.3f Mbps" % [size*lo*para/elapsed/1000/1000]
148
+ puts "% 10.3f records/sec" % [lo*para*multi/elapsed]
149
+ end
150
+
151
+ end
152
+
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "fluent-plugin-combiner"
7
- spec.version = "0.0.1"
7
+ spec.version = "0.0.2"
8
8
  spec.authors = ["karahiyo"]
9
9
  spec.email = ["a.ryuklnm@gmail.com"]
10
10
  spec.summary = "Combine buffer output data to cut-down net-i/o load"
@@ -3,8 +3,8 @@ module Fluent
3
3
  Fluent::Plugin.register_output('combiner', self)
4
4
 
5
5
  # config_param :hoge, :string, :default => 'hoge'
6
- config_param :tag, :string, :default => 'combined'
7
- config_param :tag_prefix, :string, :default => nil
6
+ config_param :tag, :string, :default => nil
7
+ config_param :tag_prefix, :string, :default => 'combined'
8
8
  config_param :input_tag_remove_prefix, :string, :default => nil
9
9
  config_param :count_interval, :time, :default => 60
10
10
  config_param :count_key, :string, :default => 'keys'
@@ -21,7 +21,8 @@ module Fluent
21
21
  super
22
22
 
23
23
  @tick = @count_interval.to_i if @count_interval
24
- @tag_prefix_string = @tag_prefix ? @tag_prefix + '.' : @tag + '.'
24
+ @tag_str = @tag + '.' if @tag
25
+ @tag_prefix_string = @tag_prefix + '.' if @tag_prefix
25
26
  if @input_tag_remove_prefix
26
27
  @remove_prefix_string = @input_tag_remove_prefix + '.'
27
28
  @remove_prefix_length = @remove_prefix_string.length
@@ -49,13 +50,20 @@ module Fluent
49
50
 
50
51
  def flush_emit
51
52
  flushed = flush
52
- Fluent::Engine.emit(@tag, Fluent::Engine.now, flushed)
53
+ now = Fluent::Engine.now
54
+ flushed.each do |tag, message|
55
+ Fluent::Engine.emit(tag, now, message)
56
+ end
53
57
  end
54
58
 
55
59
  def generate_output(data)
56
60
  output = {}
57
61
  data.each do |tag, hist|
58
- output[add_prefix(stripped_tag(tag))] = hist
62
+ if @tag
63
+ output[@tag] = hist
64
+ else
65
+ output[add_prefix(stripped_tag(tag))] = hist
66
+ end
59
67
  end
60
68
  output
61
69
  end
@@ -19,7 +19,7 @@ class CombinerOutputTest < Test::Unit::TestCase
19
19
  def test_configure
20
20
  d = create_driver
21
21
  assert_equal 5, d.instance.tick
22
- assert_equal 'combined', d.instance.tag
22
+ assert_equal nil, d.instance.tag
23
23
  assert_equal 'keys', d.instance.count_key
24
24
  assert_equal 'combined', d.instance.tag_prefix
25
25
  assert_equal 'test.input', d.instance.input_tag_remove_prefix
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-combiner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - karahiyo
@@ -64,6 +64,8 @@ files:
64
64
  - LICENSE.txt
65
65
  - README.md
66
66
  - Rakefile
67
+ - bench/README.md
68
+ - bench/genload.rb
67
69
  - fluent-plugin-combiner.gemspec
68
70
  - lib/fluent/plugin/out_combiner.rb
69
71
  - test/helper.rb