fluent-plugin-delay-inspector 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +45 -0
- data/Rakefile +11 -0
- data/fluent-plugin-delay-inspector.gemspec +20 -0
- data/lib/fluent/plugin/out_delay_inspector.rb +58 -0
- data/test/helper.rb +28 -0
- data/test/plugin/test_out_delay_inspector.rb +110 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 TAGOMORI Satoshi
|
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,45 @@
|
|
1
|
+
# fluent-plugin-delay-inspector
|
2
|
+
|
3
|
+
## DelayInspectorOutput
|
4
|
+
|
5
|
+
Fluentd plugin to inspect diff of real-time and log-time, and emit message as:
|
6
|
+
|
7
|
+
* new message with single key-value pair (DEFAULT)
|
8
|
+
* whole message with original attributes and injected delay information (with `reserve_data true`)
|
9
|
+
|
10
|
+
## Configuration
|
11
|
+
|
12
|
+
To get delay information only with specified tag `delayinfo` and key name `delay`(default):
|
13
|
+
|
14
|
+
<match message.whatever.**>
|
15
|
+
type delay_inspector
|
16
|
+
tag delayinfo
|
17
|
+
</match>
|
18
|
+
|
19
|
+
Specify `remove_prefix` and/or `add_prefix` to get tags based on original tag:
|
20
|
+
|
21
|
+
<match message.whatever.**>
|
22
|
+
type delay_inspector
|
23
|
+
remove_prefix message
|
24
|
+
add_prefix delayinfo #=> get tags as: 'delayinfo.whatever.you.want'
|
25
|
+
</match>
|
26
|
+
|
27
|
+
To add delay info into original messages with specified key name (and pass these to other plugins):
|
28
|
+
|
29
|
+
<match raw.message.whatever.**>
|
30
|
+
type delay_inspector
|
31
|
+
remove_prefix raw
|
32
|
+
key_name delay_seconds
|
33
|
+
reserve_data yes
|
34
|
+
</match>
|
35
|
+
|
36
|
+
## TODO
|
37
|
+
|
38
|
+
* patches welcome!
|
39
|
+
|
40
|
+
## Copyright
|
41
|
+
|
42
|
+
* Copyright
|
43
|
+
* Copyright (c) 2012- TAGOMORI Satoshi (tagomoris)
|
44
|
+
* License
|
45
|
+
* Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "fluent-plugin-delay-inspector"
|
5
|
+
gem.version = "0.0.1"
|
6
|
+
gem.authors = ["TAGOMORI Satoshi"]
|
7
|
+
gem.email = ["tagomoris@gmail.com"]
|
8
|
+
gem.summary = %q{Fluentd plugin to inspect diff of real-time and log-time}
|
9
|
+
gem.description = %q{Inspect delay of log, and emit it, or inject it into message itself with specified attribute name}
|
10
|
+
gem.homepage = "https://github.com/tagomoris/fluent-plugin-delay-inspector"
|
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_development_dependency "fluentd"
|
18
|
+
gem.add_development_dependency "rake"
|
19
|
+
gem.add_runtime_dependency "fluentd"
|
20
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Fluent::DelayInspectorOutput < Fluent::Output
|
2
|
+
Fluent::Plugin.register_output('delay_inspector', self)
|
3
|
+
|
4
|
+
config_param :tag, :string, :default => nil
|
5
|
+
config_param :remove_prefix, :string, :default => nil
|
6
|
+
config_param :add_prefix, :string, :default => nil
|
7
|
+
|
8
|
+
config_param :key_name, :string, :default => 'delay'
|
9
|
+
config_param :reserve_data, :bool, :default => false
|
10
|
+
|
11
|
+
def configure(conf)
|
12
|
+
super
|
13
|
+
|
14
|
+
if not @tag and not @remove_prefix and not @add_prefix
|
15
|
+
raise Fluent::ConfigError, "missing both of remove_prefix and add_prefix"
|
16
|
+
end
|
17
|
+
if @tag and (@remove_prefix or @add_prefix)
|
18
|
+
raise Fluent::ConfigError, "both of tag and remove_prefix/add_prefix must not be specified"
|
19
|
+
end
|
20
|
+
if @remove_prefix
|
21
|
+
@removed_prefix_string = @remove_prefix + '.'
|
22
|
+
@removed_length = @removed_prefix_string.length
|
23
|
+
end
|
24
|
+
if @add_prefix
|
25
|
+
@added_prefix_string = @add_prefix + '.'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def emit(tag, es, chain)
|
30
|
+
tag = if @tag
|
31
|
+
@tag
|
32
|
+
else
|
33
|
+
if @remove_prefix and
|
34
|
+
( (tag.start_with?(@removed_prefix_string) and tag.length > @removed_length) or tag == @remove_prefix)
|
35
|
+
tag = tag[@removed_length..-1]
|
36
|
+
end
|
37
|
+
if @add_prefix
|
38
|
+
tag = if tag and tag.length > 0
|
39
|
+
@added_prefix_string + tag
|
40
|
+
else
|
41
|
+
@add_prefix
|
42
|
+
end
|
43
|
+
end
|
44
|
+
tag
|
45
|
+
end
|
46
|
+
if @reserve_data
|
47
|
+
es.each do |time,record|
|
48
|
+
record[@key_name] = Fluent::Engine.now - time
|
49
|
+
Fluent::Engine.emit(tag, time, record)
|
50
|
+
end
|
51
|
+
else
|
52
|
+
es.each do |time,record|
|
53
|
+
Fluent::Engine.emit(tag, time, {@key_name => (Fluent::Engine.now - time)})
|
54
|
+
end
|
55
|
+
end
|
56
|
+
chain.next
|
57
|
+
end
|
58
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
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
|
+
unless ENV.has_key?('VERBOSE')
|
16
|
+
nulllogger = Object.new
|
17
|
+
nulllogger.instance_eval {|obj|
|
18
|
+
def method_missing(method, *args)
|
19
|
+
# pass
|
20
|
+
end
|
21
|
+
}
|
22
|
+
$log = nulllogger
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'fluent/plugin/out_delay_inspector'
|
26
|
+
|
27
|
+
class Test::Unit::TestCase
|
28
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class DelayInspectorOutputTest < Test::Unit::TestCase
|
4
|
+
def setup
|
5
|
+
Fluent::Test.setup
|
6
|
+
end
|
7
|
+
|
8
|
+
CONFIG1 = %[
|
9
|
+
tag delay.info
|
10
|
+
]
|
11
|
+
CONFIG2 = %[
|
12
|
+
add_prefix fixed
|
13
|
+
key_name delayinfo
|
14
|
+
]
|
15
|
+
CONFIG3 = %[
|
16
|
+
remove_prefix before
|
17
|
+
add_prefix after
|
18
|
+
reserve_data true
|
19
|
+
]
|
20
|
+
|
21
|
+
def create_driver(conf=CONFIG1, tag='test')
|
22
|
+
Fluent::Test::OutputTestDriver.new(Fluent::DelayInspectorOutput, tag).configure(conf)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_configure
|
26
|
+
assert_raise(Fluent::ConfigError) {
|
27
|
+
d = create_driver('')
|
28
|
+
}
|
29
|
+
assert_nothing_raised {
|
30
|
+
d = create_driver %[
|
31
|
+
tag foo
|
32
|
+
]
|
33
|
+
}
|
34
|
+
assert_nothing_raised {
|
35
|
+
d = create_driver %[
|
36
|
+
remove_prefix bar
|
37
|
+
]
|
38
|
+
}
|
39
|
+
|
40
|
+
d = create_driver
|
41
|
+
assert_equal 'delay', d.instance.key_name
|
42
|
+
assert_equal false, d.instance.reserve_data
|
43
|
+
|
44
|
+
d3 = create_driver(CONFIG3)
|
45
|
+
assert_equal true, d3.instance.reserve_data
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_emit1
|
49
|
+
d1 = create_driver(CONFIG1, 'whatever')
|
50
|
+
time = Time.now.to_i - 3
|
51
|
+
d1.run do
|
52
|
+
d1.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
53
|
+
d1.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
54
|
+
end
|
55
|
+
emits = d1.emits
|
56
|
+
assert_equal 2, emits.length
|
57
|
+
|
58
|
+
assert_equal 'delay.info', emits[0][0]
|
59
|
+
assert_equal time, emits[0][1]
|
60
|
+
assert_equal ['delay'], emits[0][2].keys
|
61
|
+
assert ( 3 <= emits[0][2]['delay'].to_i && emits[0][2]['delay'] <= 4 )
|
62
|
+
|
63
|
+
assert_equal 'delay.info', emits[1][0]
|
64
|
+
assert_equal time, emits[1][1]
|
65
|
+
assert_equal ['delay'], emits[1][2].keys
|
66
|
+
assert ( 3 <= emits[1][2]['delay'].to_i && emits[1][2]['delay'] <= 4 )
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_emit2
|
70
|
+
d1 = create_driver(CONFIG2, 'whatever')
|
71
|
+
time = Time.now.to_i - 3
|
72
|
+
d1.run do
|
73
|
+
d1.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
74
|
+
d1.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
75
|
+
end
|
76
|
+
emits = d1.emits
|
77
|
+
assert_equal 2, emits.length
|
78
|
+
|
79
|
+
assert_equal 'fixed.whatever', emits[0][0]
|
80
|
+
assert_equal time, emits[0][1]
|
81
|
+
assert_equal ['delayinfo'], emits[0][2].keys
|
82
|
+
assert ( 3 <= emits[0][2]['delayinfo'].to_i && emits[0][2]['delayinfo'] <= 4 )
|
83
|
+
|
84
|
+
assert_equal 'fixed.whatever', emits[1][0]
|
85
|
+
assert_equal time, emits[1][1]
|
86
|
+
assert_equal ['delayinfo'], emits[1][2].keys
|
87
|
+
assert ( 3 <= emits[1][2]['delayinfo'].to_i && emits[1][2]['delayinfo'] <= 4 )
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_emit3
|
91
|
+
d1 = create_driver(CONFIG3, 'before.whatever')
|
92
|
+
time = Time.now.to_i - 3
|
93
|
+
d1.run do
|
94
|
+
d1.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
95
|
+
d1.emit({'foo' => 'bar', 'baz' => 'boo'}, time)
|
96
|
+
end
|
97
|
+
emits = d1.emits
|
98
|
+
assert_equal 2, emits.length
|
99
|
+
|
100
|
+
assert_equal 'after.whatever', emits[0][0]
|
101
|
+
assert_equal time, emits[0][1]
|
102
|
+
assert_equal ['baz', 'delay', 'foo'], emits[0][2].keys.sort
|
103
|
+
assert ( 3 <= emits[0][2]['delay'].to_i && emits[0][2]['delay'] <= 4 )
|
104
|
+
|
105
|
+
assert_equal 'after.whatever', emits[1][0]
|
106
|
+
assert_equal time, emits[1][1]
|
107
|
+
assert_equal ['baz', 'delay', 'foo'], emits[0][2].keys.sort
|
108
|
+
assert ( 3 <= emits[1][2]['delay'].to_i && emits[1][2]['delay'] <= 4 )
|
109
|
+
end
|
110
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-delay-inspector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- TAGOMORI Satoshi
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: fluentd
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: fluentd
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Inspect delay of log, and emit it, or inject it into message itself with
|
63
|
+
specified attribute name
|
64
|
+
email:
|
65
|
+
- tagomoris@gmail.com
|
66
|
+
executables: []
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- fluent-plugin-delay-inspector.gemspec
|
76
|
+
- lib/fluent/plugin/out_delay_inspector.rb
|
77
|
+
- test/helper.rb
|
78
|
+
- test/plugin/test_out_delay_inspector.rb
|
79
|
+
homepage: https://github.com/tagomoris/fluent-plugin-delay-inspector
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.21
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Fluentd plugin to inspect diff of real-time and log-time
|
103
|
+
test_files:
|
104
|
+
- test/helper.rb
|
105
|
+
- test/plugin/test_out_delay_inspector.rb
|