fluent-plugin-mqtt 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/fluent-plugin-mqtt.gemspec +1 -1
- data/lib/fluent/plugin/out_mqtt.rb +42 -22
- data/test/helper.rb +3 -0
- data/test/plugin/test_out_mqtt.rb +118 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87146ea70041d0d56d3a6c9db7f6cf8a1096bd9a
|
4
|
+
data.tar.gz: fe84c1296c4e329dbca1e794e0e3fd177a415666
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d4f98038168c1a48cd50911ee8e6f3ff617ffa66a5cef78ce0db37c13c13d378527025eee7d17715f5e1356ec3526bfef6737a66fe691e0ab6347ecc98122c0
|
7
|
+
data.tar.gz: 841606034f3c2b74a22c4e8e8c812d29571987b6ab57efe004b811959ed41f946809d03f8e0c609eb1fd8b5118a3bdab370584be37fd57dfaf833aac35602b09
|
data/fluent-plugin-mqtt.gemspec
CHANGED
@@ -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-mqtt"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.9"
|
8
8
|
spec.authors = ["Yuuna Kurita"]
|
9
9
|
spec.email = ["yuuna.m@gmail.com"]
|
10
10
|
spec.summary = %q{fluentd input plugin for mqtt server}
|
@@ -1,14 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require 'mqtt'
|
2
|
+
require 'msgpack'
|
3
|
+
require 'fluent/plugin/output'
|
4
|
+
|
5
|
+
module Fluent::Plugin
|
6
|
+
class OutMqtt < Output
|
7
|
+
Fluent::Plugin.register_output('mqtt', self)
|
8
|
+
|
9
|
+
helpers :compat_parameters, :inject, :formatter
|
10
|
+
|
11
|
+
DEFAULT_BUFFER_TYPE = "memory"
|
4
12
|
|
5
|
-
include Fluent::SetTagKeyMixin
|
6
13
|
config_set_default :include_tag_key, false
|
7
|
-
|
8
|
-
include Fluent::SetTimeKeyMixin
|
9
14
|
config_set_default :include_time_key, true
|
10
15
|
|
11
|
-
|
12
16
|
config_param :port, :integer, :default => 1883
|
13
17
|
config_param :bind, :string, :default => '127.0.0.1'
|
14
18
|
config_param :topic, :string, :default => 'td-agent'
|
@@ -22,15 +26,19 @@ module Fluent
|
|
22
26
|
config_param :cert, :string, :default => nil
|
23
27
|
config_param :retain, :string, :default => true
|
24
28
|
|
25
|
-
|
29
|
+
config_section :buffer do
|
30
|
+
config_set_default :@type, DEFAULT_BUFFER_TYPE
|
31
|
+
config_set_default :chunk_keys, ['tag']
|
32
|
+
end
|
26
33
|
|
27
|
-
|
28
|
-
|
34
|
+
config_section :inject do
|
35
|
+
config_set_default :time_key, "time"
|
36
|
+
config_set_default :time_type, "string"
|
37
|
+
config_set_default :time_format, "%Y-%m-%dT%H:%M:%S%z"
|
29
38
|
end
|
30
39
|
|
31
40
|
def initialize
|
32
41
|
super
|
33
|
-
require 'msgpack'
|
34
42
|
|
35
43
|
@clients = {}
|
36
44
|
@connection_options = {}
|
@@ -38,19 +46,21 @@ module Fluent
|
|
38
46
|
end
|
39
47
|
|
40
48
|
def configure(conf)
|
49
|
+
compat_parameters_convert(conf, :buffer, :inject, :formatter)
|
41
50
|
super
|
42
51
|
@bind ||= conf['bind']
|
43
52
|
@topic ||= conf['topic']
|
44
53
|
@port ||= conf['port']
|
45
|
-
@formatter =
|
46
|
-
|
54
|
+
@formatter = formatter_create
|
55
|
+
if conf.has_key?('buffer_chunk_limit')
|
56
|
+
#check buffer_size
|
57
|
+
conf['buffer_chunk_limit'] = available_buffer_chunk_limit(conf)
|
58
|
+
end
|
47
59
|
end
|
48
60
|
|
49
61
|
def start
|
50
|
-
#check buffer_size
|
51
|
-
@buffer.buffer_chunk_limit = available_buffer_chunk_limit
|
52
62
|
|
53
|
-
|
63
|
+
log.debug "start mqtt #{@bind}"
|
54
64
|
opts = {host: @bind,
|
55
65
|
port: @port}
|
56
66
|
opts[:client_id] = @client_id if @client_id
|
@@ -70,11 +80,21 @@ module Fluent
|
|
70
80
|
end
|
71
81
|
|
72
82
|
def format(tag, time, record)
|
73
|
-
[
|
83
|
+
[time, record].to_msgpack
|
84
|
+
end
|
85
|
+
|
86
|
+
def formatted_to_msgpack_binary
|
87
|
+
true
|
88
|
+
end
|
89
|
+
|
90
|
+
def multi_workers_ready?
|
91
|
+
true
|
74
92
|
end
|
75
93
|
|
76
94
|
def write(chunk)
|
77
|
-
chunk.
|
95
|
+
tag = chunk.metadata.tag
|
96
|
+
chunk.msgpack_each { |time, record|
|
97
|
+
record = inject_values_to_record(tag, time, record)
|
78
98
|
log.debug "write #{@topic} #{@formatter.format(tag,time,record)}"
|
79
99
|
@connect.publish(@topic, @formatter.format(tag,time,record), retain=@retain)
|
80
100
|
}
|
@@ -84,12 +104,12 @@ module Fluent
|
|
84
104
|
# Following limits are heuristic. BSON is sometimes bigger than MessagePack and JSON.
|
85
105
|
LIMIT_MQTT = 2 * 1024 # 2048kb
|
86
106
|
|
87
|
-
def available_buffer_chunk_limit
|
88
|
-
if
|
89
|
-
log.warn ":buffer_chunk_limit(#{
|
107
|
+
def available_buffer_chunk_limit(conf)
|
108
|
+
if conf['buffer_chunk_limit'] > LIMIT_MQTT
|
109
|
+
log.warn ":buffer_chunk_limit(#{conf['buffer_chunk_limit']}) is large. Reset :buffer_chunk_limit with #{LIMIT_MQTT}"
|
90
110
|
LIMIT_MQTT
|
91
111
|
else
|
92
|
-
|
112
|
+
conf['buffer_chunk_limit']
|
93
113
|
end
|
94
114
|
end
|
95
115
|
end
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,118 @@
|
|
1
|
+
require_relative '../helper'
|
2
|
+
require 'fluent/test/driver/output'
|
3
|
+
|
4
|
+
class MqttOutputTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
Fluent::Test.setup
|
7
|
+
end
|
8
|
+
|
9
|
+
CONFIG = %[ bind 127.0.0.1
|
10
|
+
port 1883
|
11
|
+
format json ]
|
12
|
+
|
13
|
+
def create_driver(conf = CONFIG)
|
14
|
+
Fluent::Test::Driver::Output.new(Fluent::Plugin::OutMqtt).configure(conf)
|
15
|
+
end
|
16
|
+
|
17
|
+
def sub_client(topic = "td-agent/#")
|
18
|
+
connect = MQTT::Client.connect("localhost")
|
19
|
+
connect.subscribe(topic)
|
20
|
+
return connect
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_configure_1
|
24
|
+
d = create_driver(
|
25
|
+
%[ bind 127.0.0.1
|
26
|
+
port 1883
|
27
|
+
format json]
|
28
|
+
)
|
29
|
+
assert_equal '127.0.0.1', d.instance.bind
|
30
|
+
assert_equal 1883, d.instance.port
|
31
|
+
assert_equal 'json', d.instance.instance_variable_get(:@format)
|
32
|
+
|
33
|
+
d2 = create_driver(
|
34
|
+
%[ bind 127.0.0.1
|
35
|
+
port 1883
|
36
|
+
format csv
|
37
|
+
fields time,message
|
38
|
+
time_key time]
|
39
|
+
)
|
40
|
+
assert_equal 'csv', d2.instance.instance_variable_get(:@format)
|
41
|
+
assert_equal 'time', d2.instance.inject_config.time_key
|
42
|
+
end
|
43
|
+
|
44
|
+
class TestWithTimeZone < self
|
45
|
+
def setup
|
46
|
+
@timeZone = ENV['TZ']
|
47
|
+
end
|
48
|
+
def teardown
|
49
|
+
ENV['TZ'] = @timeZone
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_format_csv
|
53
|
+
ENV['TZ'] = 'Asia/Tokyo'
|
54
|
+
|
55
|
+
d = create_driver(
|
56
|
+
%[ bind 127.0.0.1
|
57
|
+
port 1883
|
58
|
+
format csv
|
59
|
+
time_type string
|
60
|
+
time_format %Y-%m-%dT%H:%M:%S%z
|
61
|
+
fields time,message]
|
62
|
+
)
|
63
|
+
|
64
|
+
client = sub_client
|
65
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
66
|
+
data = [
|
67
|
+
{tag: "tag1", message: "#{time},hello world" },
|
68
|
+
{tag: "tag2", message: "#{time},hello to you to" },
|
69
|
+
{tag: "tag3", message: "#{time}," },
|
70
|
+
]
|
71
|
+
|
72
|
+
d.run(default_tag: "test") do
|
73
|
+
data.each do |record|
|
74
|
+
d.feed(time, record)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
3.times do |i|
|
78
|
+
record = client.get
|
79
|
+
assert_equal "td-agent", record[0]
|
80
|
+
assert_equal "\"2011-01-02T22:14:15+0900\",\"#{data[i][:message]}\"\n", record[1]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_format_json
|
85
|
+
ENV['TZ'] = 'Asia/Tokyo'
|
86
|
+
|
87
|
+
d = create_driver(
|
88
|
+
%[ bind 127.0.0.1
|
89
|
+
port 1883
|
90
|
+
format json
|
91
|
+
time_type string
|
92
|
+
time_format %Y-%m-%dT%H:%M:%S%z
|
93
|
+
fields time,message]
|
94
|
+
)
|
95
|
+
|
96
|
+
client = sub_client
|
97
|
+
time = event_time("2011-01-02 13:14:15 UTC")
|
98
|
+
data = [
|
99
|
+
{tag: "tag1", message: "#{time},hello world" },
|
100
|
+
{tag: "tag2", message: "#{time},hello to you to" },
|
101
|
+
{tag: "tag3", message: "#{time}," },
|
102
|
+
]
|
103
|
+
|
104
|
+
d.run(default_tag: "test") do
|
105
|
+
data.each do |record|
|
106
|
+
d.feed(time, record)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
3.times do |i|
|
110
|
+
record = client.get
|
111
|
+
assert_equal "td-agent", record[0]
|
112
|
+
assert_equal "{\"tag\":\"#{data[i][:tag]}\",\
|
113
|
+
\"message\":\"#{data[i][:message]}\",\
|
114
|
+
\"time\":\"2011-01-02T22:14:15+0900\"}\n", record[1]
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mqtt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuuna Kurita
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mqtt
|
@@ -111,6 +111,7 @@ files:
|
|
111
111
|
- lib/fluent/plugin/out_mqtt.rb
|
112
112
|
- test/helper.rb
|
113
113
|
- test/plugin/test_in_mqtt.rb
|
114
|
+
- test/plugin/test_out_mqtt.rb
|
114
115
|
homepage: http://github.com/yuuna/fluent-plugin-mqtt
|
115
116
|
licenses:
|
116
117
|
- MIT
|
@@ -131,10 +132,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
132
|
version: '0'
|
132
133
|
requirements: []
|
133
134
|
rubyforge_project:
|
134
|
-
rubygems_version: 2.
|
135
|
+
rubygems_version: 2.6.11
|
135
136
|
signing_key:
|
136
137
|
specification_version: 4
|
137
138
|
summary: fluentd input plugin for mqtt server
|
138
139
|
test_files:
|
139
140
|
- test/helper.rb
|
140
141
|
- test/plugin/test_in_mqtt.rb
|
142
|
+
- test/plugin/test_out_mqtt.rb
|