fluent-plugin-5rocks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +54 -0
- data/Rakefile +11 -0
- data/fluent-plugin-5rocks.gemspec +24 -0
- data/lib/fluent/plugin/out_5rocks.rb +77 -0
- data/test/helper.rb +30 -0
- data/test/plugin/test_out_5rocks.rb +128 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 469f6033d209b5faea327124c20b2c74768feed4
|
4
|
+
data.tar.gz: d0b9ef4ef01610728efecb1f0636413c630a6073
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a82fcf3dfe702cb911dbc26a93cf06e82869ce942b6758da4a223ac3c56a448cdcd634902700a0c1924d0a9238db904209a2231ee148dae8928c04fbabca905
|
7
|
+
data.tar.gz: e1b65ee8d2788dc4df761c8ab22047a77d29dacd9cb0d9cefe424c029ad065eda9757310799cfbf2818d0cc50f3aa36ec95a8284fe701138c9cd1860d7db6352
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 hokuts
|
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,54 @@
|
|
1
|
+
# fluent-plugin-5rocks
|
2
|
+
|
3
|
+
[Fluentd](http://fluentd.org) output plugin to insert data into [5rocks](https://www.5rocks.io/) database.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'fluent-plugin-5rocks'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install fluent-plugin-5rocks
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
```apache
|
24
|
+
<match dummy>
|
25
|
+
type 5rocks
|
26
|
+
|
27
|
+
app_id xxxxxxxxxxxxxxxx
|
28
|
+
app_key XXXXXXXXXXXXXXXXX
|
29
|
+
|
30
|
+
<field>
|
31
|
+
type custom
|
32
|
+
name test_from_plugin
|
33
|
+
category cat_1
|
34
|
+
p1 test_p_1
|
35
|
+
p2 test_p_2
|
36
|
+
user_id test_user
|
37
|
+
uv1 $(fld_s)
|
38
|
+
uv2 $(fld_t)
|
39
|
+
<values>
|
40
|
+
abc $(fld_i)
|
41
|
+
</values>
|
42
|
+
</field>
|
43
|
+
</match>
|
44
|
+
```
|
45
|
+
|
46
|
+
`$(xxx)` expression is provided to load a field data from a fluentd record.
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
1. Fork it ( https://github.com/groovenauts/fluent-plugin-5rocks/fork )
|
51
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
52
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
54
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "fluent-plugin-5rocks"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["hokuts"]
|
9
|
+
spec.email = ["hokuto.sh@gmail.com"]
|
10
|
+
spec.summary = %q{Fluentd plugin to store data into 5Rocks}
|
11
|
+
# spec.description = %q{TODO: Write a longer description. Optional.}
|
12
|
+
spec.homepage = ""
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_runtime_dependency "fluentd"
|
23
|
+
spec.add_development_dependency "webmock"
|
24
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
class Fluent::FiveRocksOutput < Fluent::BufferedOutput
|
2
|
+
Fluent::Plugin.register_output('5rocks', self)
|
3
|
+
|
4
|
+
config_param :url_base, :string, :default => "https://server.api.5rocks.io/sev/1/"
|
5
|
+
|
6
|
+
attr_reader :url, :field_map
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
require 'net/http'
|
11
|
+
require 'uri'
|
12
|
+
require "time"
|
13
|
+
end
|
14
|
+
|
15
|
+
def configure(conf)
|
16
|
+
super
|
17
|
+
@url = "#{@url_base}#{conf['app_id']}"
|
18
|
+
@field_map = {
|
19
|
+
'app_key' => conf['app_key'],
|
20
|
+
'name' => conf['name'],
|
21
|
+
}
|
22
|
+
@field_map['category'] = conf['category'] if conf['category']
|
23
|
+
conf.elements.select { |e|
|
24
|
+
e.name == "field"
|
25
|
+
}.each { |f|
|
26
|
+
f.each_key { |k| @field_map[k] = f[k]}
|
27
|
+
|
28
|
+
f.elements.select { |ee|
|
29
|
+
ee.name == "values"
|
30
|
+
}.each { |m|
|
31
|
+
m.each_key{ |k| @field_map["values[#{k}]"] = m[k]}
|
32
|
+
}
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def start
|
37
|
+
super
|
38
|
+
end
|
39
|
+
|
40
|
+
def shutdown
|
41
|
+
super
|
42
|
+
end
|
43
|
+
|
44
|
+
def format(tag, time, record)
|
45
|
+
[tag, time, record].to_msgpack
|
46
|
+
end
|
47
|
+
|
48
|
+
def write(chunk)
|
49
|
+
ret = []
|
50
|
+
chunk.msgpack_each do |tag, time, record|
|
51
|
+
log.debug "tag: #{tag}, record: #{record}"
|
52
|
+
|
53
|
+
params = @field_map.each_with_object({}) do |(k, v), p|
|
54
|
+
if /^\$\(([^)]+)\)$/ =~ v
|
55
|
+
p[k] = record[$1] # can be ::String, ::Numeric, etc.
|
56
|
+
else
|
57
|
+
p[k] = v ? v.gsub(/\$\(([^)]+)\)/) { record[$1] } : nil # ::String
|
58
|
+
end
|
59
|
+
end
|
60
|
+
t = params["time"] || time
|
61
|
+
t = Time.parse(t) if t.is_a?(::String)
|
62
|
+
t = t.to_f * 1000 if t.is_a?(::Date) or t.is_a?(::Time)
|
63
|
+
t = [t / 1000, t, t * 1000].min_by { |_t| (Time.now.to_f * 1000 - _t).abs } # to milliseconds
|
64
|
+
t = t.to_i
|
65
|
+
params["time"] = t
|
66
|
+
|
67
|
+
log.debug "request parameters: #{params}"
|
68
|
+
res = Net::HTTP.post_form(URI.parse(@url), params)
|
69
|
+
log.debug "response code: #{res.code}"
|
70
|
+
log.debug "response body: #{res.body}"
|
71
|
+
|
72
|
+
ret << params
|
73
|
+
raise "failed to insert into 5rocks" unless res.code == "201"
|
74
|
+
end
|
75
|
+
return ret
|
76
|
+
end
|
77
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
begin
|
5
|
+
Bundler.setup(:default, :development)
|
6
|
+
rescue Bundler::BundlerError => e
|
7
|
+
$stderr.puts e.message
|
8
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
+
exit e.status_code
|
10
|
+
end
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'fluent/test'
|
16
|
+
unless ENV.has_key?('VERBOSE')
|
17
|
+
nulllogger = Object.new
|
18
|
+
nulllogger.instance_eval {|obj|
|
19
|
+
def method_missing(method, *args)
|
20
|
+
# pass
|
21
|
+
end
|
22
|
+
}
|
23
|
+
$log = nulllogger
|
24
|
+
end
|
25
|
+
|
26
|
+
require 'fluent/plugin/out_5rocks'
|
27
|
+
require 'webmock/test_unit'
|
28
|
+
|
29
|
+
class Test::Unit::TestCase
|
30
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'helper'
|
2
|
+
# require 'time'
|
3
|
+
|
4
|
+
class FiveRocksOutputTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
Fluent::Test.setup
|
8
|
+
end
|
9
|
+
|
10
|
+
CONFIG = %[
|
11
|
+
app_id test_app_id
|
12
|
+
app_key test_app_key
|
13
|
+
<field>
|
14
|
+
type custom
|
15
|
+
name test_from_plugin
|
16
|
+
category cat_a
|
17
|
+
p1 prefix_$(data_key)
|
18
|
+
<values>
|
19
|
+
key_a val_a
|
20
|
+
key_b $(data_key)
|
21
|
+
</values>
|
22
|
+
</field>
|
23
|
+
]
|
24
|
+
|
25
|
+
def create_driver(conf=CONFIG)
|
26
|
+
Fluent::Test::BufferedOutputTestDriver.new(Fluent::FiveRocksOutput).configure(conf)
|
27
|
+
end
|
28
|
+
|
29
|
+
def e(name, arg = '', attrs = {}, elements = [])
|
30
|
+
attrs = attrs.inject({}){ |m, (k, v)| m[k.to_s] = v; m }
|
31
|
+
Fluent::Config::Element.new(name, arg, attrs, elements)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_configure
|
35
|
+
### set configurations
|
36
|
+
d = create_driver
|
37
|
+
### check configurations
|
38
|
+
assert_equal 'https://server.api.5rocks.io/sev/1/test_app_id', d.instance.url
|
39
|
+
expected = {
|
40
|
+
"app_key" => "test_app_key",
|
41
|
+
"type" => "custom",
|
42
|
+
"name" => "test_from_plugin",
|
43
|
+
"category" => "cat_a",
|
44
|
+
"p1" => "prefix_$(data_key)",
|
45
|
+
"values[key_a]" => "val_a",
|
46
|
+
"values[key_b]" => "$(data_key)",
|
47
|
+
}
|
48
|
+
assert_equal expected, d.instance.field_map
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_format_and_write
|
52
|
+
d = create_driver
|
53
|
+
|
54
|
+
time = Time.parse("2014-12-08 18:20:30 UTC").to_i
|
55
|
+
d.emit({"data_key" => 7}, time)
|
56
|
+
d.emit({"data_key" => 5}, time)
|
57
|
+
|
58
|
+
d.expect_format ["test", time, {"data_key" => 7}].to_msgpack
|
59
|
+
d.expect_format ["test", time, {"data_key" => 5}].to_msgpack
|
60
|
+
|
61
|
+
stub_request(:post, 'https://server.api.5rocks.io/sev/1/test_app_id').to_return(:status => [201, "Created"])
|
62
|
+
params = d.run
|
63
|
+
expected = [
|
64
|
+
{
|
65
|
+
"app_key" => "test_app_key", "type" => "custom", "name" => "test_from_plugin", "category" => "cat_a",
|
66
|
+
"p1" => "prefix_7", "values[key_a]" => "val_a", "values[key_b]" => 7, "time" => (time * 1000).to_i
|
67
|
+
},
|
68
|
+
{
|
69
|
+
"app_key" => "test_app_key", "type" => "custom", "name" => "test_from_plugin", "category" => "cat_a",
|
70
|
+
"p1" => "prefix_5", "values[key_a]" => "val_a", "values[key_b]" => 5, "time" => (time * 1000).to_i
|
71
|
+
}
|
72
|
+
]
|
73
|
+
assert_equal expected, params
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_format_and_write_dfferent_time
|
77
|
+
times = [
|
78
|
+
Time.parse("2014-12-08 18:10:00 UTC"),
|
79
|
+
Time.parse("2014-12-08 18:10:01 UTC"),
|
80
|
+
]
|
81
|
+
d = create_driver(%[
|
82
|
+
app_id test_app_id
|
83
|
+
app_key test_app_key
|
84
|
+
<field>
|
85
|
+
type custom
|
86
|
+
name test_from_plugin
|
87
|
+
category cat_a
|
88
|
+
p1 prefix_$(data_key)
|
89
|
+
p2 $(data_key)$(data_key)
|
90
|
+
time $(time)
|
91
|
+
<values>
|
92
|
+
key_a val_a
|
93
|
+
key_b $(data_key)
|
94
|
+
</values>
|
95
|
+
</field>
|
96
|
+
])
|
97
|
+
|
98
|
+
d.emit({"data_key" => 7, "time" => times[0].to_i}, times[1].to_i) # sec
|
99
|
+
d.emit({"data_key" => 5, "time" => (times[0].to_f * 1000).to_i}, times[1].to_i) # millisec
|
100
|
+
d.emit({"data_key" => 3, "time" => (times[0].to_f * 1000000).to_i}, times[1].to_i) # microsec
|
101
|
+
|
102
|
+
d.expect_format ["test", times[1].to_i, {"data_key" => 7, "time" => times[0].to_i}].to_msgpack
|
103
|
+
d.expect_format ["test", times[1].to_i, {"data_key" => 5, "time" => (times[0].to_f * 1000).to_i}].to_msgpack
|
104
|
+
d.expect_format ["test", times[1].to_i, {"data_key" => 3, "time" => (times[0].to_f * 1000000).to_i}].to_msgpack
|
105
|
+
|
106
|
+
stub_request(:post, 'https://server.api.5rocks.io/sev/1/test_app_id').to_return(:status => [201, "Created"])
|
107
|
+
params = d.run
|
108
|
+
expected = [
|
109
|
+
{
|
110
|
+
"app_key" => "test_app_key", "type" => "custom", "name" => "test_from_plugin", "category" => "cat_a",
|
111
|
+
"p1" => "prefix_7", "p2" => "77",
|
112
|
+
"values[key_a]" => "val_a", "values[key_b]" => 7, "time" => (times[0].to_f * 1000).to_i
|
113
|
+
},
|
114
|
+
{
|
115
|
+
"app_key" => "test_app_key", "type" => "custom", "name" => "test_from_plugin", "category" => "cat_a",
|
116
|
+
"p1" => "prefix_5", "p2" => "55",
|
117
|
+
"values[key_a]" => "val_a", "values[key_b]" => 5, "time" => (times[0].to_f * 1000).to_i
|
118
|
+
},
|
119
|
+
{
|
120
|
+
"app_key" => "test_app_key", "type" => "custom", "name" => "test_from_plugin", "category" => "cat_a",
|
121
|
+
"p1" => "prefix_3", "p2" => "33",
|
122
|
+
"values[key_a]" => "val_a", "values[key_b]" => 3, "time" => (times[0].to_f * 1000).to_i
|
123
|
+
},
|
124
|
+
]
|
125
|
+
assert_equal expected, params
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-plugin-5rocks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hokuts
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: fluentd
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: webmock
|
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:
|
70
|
+
email:
|
71
|
+
- hokuto.sh@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- .gitignore
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- fluent-plugin-5rocks.gemspec
|
82
|
+
- lib/fluent/plugin/out_5rocks.rb
|
83
|
+
- test/helper.rb
|
84
|
+
- test/plugin/test_out_5rocks.rb
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.2.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: Fluentd plugin to store data into 5Rocks
|
109
|
+
test_files:
|
110
|
+
- test/helper.rb
|
111
|
+
- test/plugin/test_out_5rocks.rb
|