fluent-plugin-mqtt-io 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +102 -3
- data/fluent-plugin-mqtt-io.gemspec +5 -3
- data/lib/fluent/plugin/in_mqtt.rb +5 -1
- metadata +27 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b35a0ac007a40c1766646e950d678848fc4eb802
|
4
|
+
data.tar.gz: a4c1b6588ca8f74bfd311ea648d65a0aa2883beb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c514b8981c952bccdd8de2aa8a7b23e9d39268dd34352301ebb6e6ae668277783abcb20f568f3138e06fbfb0c3cac685f80f35e2fe7b9201ff12a8ac2a0a83
|
7
|
+
data.tar.gz: c03a0b3312616ecea0431e1c5fdaa1c5e444ac896650fd6b7241839513baf91ce338feca03966c8e3a7e47f548157308ec4311dd98c44184aba688e53c60f554
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ Or install it yourself as:
|
|
24
24
|
|
25
25
|
## Usage
|
26
26
|
|
27
|
-
fluent-plugin-mqtt provides Input and Output Plugins for MQTT.
|
27
|
+
fluent-plugin-mqtt-io provides Input and Output Plugins for MQTT.
|
28
28
|
|
29
29
|
Input Plugin can be used via source directive in the configuration.
|
30
30
|
|
@@ -50,7 +50,8 @@ The default MQTT topic is "#". Configurable options are the following:
|
|
50
50
|
- key_file: private key file path
|
51
51
|
- cert_file: certificate file path
|
52
52
|
- format: Input parser can be chosen, e.g. json, xml
|
53
|
-
- in order to use xml format, you need to install [fluent-plugin-xml-parser](https://github.com/toyokazu/fluent-plugin-xml-parser
|
53
|
+
- in order to use xml format, you need to install [fluent-plugin-xml-parser](https://github.com/toyokazu/fluent-plugin-xml-parser).
|
54
|
+
- default format is json and default time_key for json format is 'time'
|
54
55
|
|
55
56
|
Input Plugin supports @label directive.
|
56
57
|
|
@@ -109,8 +110,106 @@ You can also use mqtt_buf type which is implemented as BufferedOutput.
|
|
109
110
|
```
|
110
111
|
|
111
112
|
|
112
|
-
##
|
113
|
+
## Use case examples
|
113
114
|
|
115
|
+
### Libelium sensor data collection
|
116
|
+
|
117
|
+
There are many kinds of commercial sensor products on the market, e.g. [Libelium](http://www.libelium.com/). Major sensor products support MQTT to upload sensor data. The following example shows how to store uploaded Libelium sensor data into ElasticSearch.
|
118
|
+
|
119
|
+
![Libelium sensor data collection](https://github.com/toyokazu/fluent-plugin-mqtt-io/blob/master/images/libelium_sensor_data_collection.png "Libelium sensor data")
|
120
|
+
|
121
|
+
As described in the figure, fluent-plugin-mqtt-io, fluent-plugin-xml-parser and fluent-plugin-elasticsearch are used. The following is an example configuration.
|
122
|
+
|
123
|
+
```
|
124
|
+
<source>
|
125
|
+
type mqtt
|
126
|
+
bind 192.168.1.100
|
127
|
+
port 1883
|
128
|
+
topic 'Libelium/+/+'
|
129
|
+
format xml
|
130
|
+
time_xpath '["cap:alert/cap:info/cap:onset", "text"]'
|
131
|
+
time_key '@timestamp'
|
132
|
+
attr_xpaths '[["cap:alert/cap:info/cap:parameter/cap:valueName", "text"]]'
|
133
|
+
value_xpaths '[["cap:alert/cap:info/cap:parameter/cap:value", "text"]]'
|
134
|
+
@label @MQTT_OUT
|
135
|
+
</source>
|
136
|
+
|
137
|
+
<label @MQTT_OUT>
|
138
|
+
<match **>
|
139
|
+
<store>
|
140
|
+
type elasticsearch
|
141
|
+
host localhost
|
142
|
+
port 9200
|
143
|
+
index_name libelium
|
144
|
+
type_name smartcity
|
145
|
+
include_tag_key true
|
146
|
+
tag_key sensor_id
|
147
|
+
logstash_format false
|
148
|
+
</store>
|
149
|
+
</match>
|
150
|
+
</label>
|
151
|
+
|
152
|
+
```
|
153
|
+
|
154
|
+
The following mapping is assumed to be created at ElasticSearch.
|
155
|
+
|
156
|
+
```
|
157
|
+
|
158
|
+
curl -XPUT 'http://localhost:9200/libelium/_mapping/smartcity' -d '
|
159
|
+
{"smartcity":
|
160
|
+
{"properties":
|
161
|
+
{
|
162
|
+
"sensor_id":{"type": "string"},
|
163
|
+
"DUST":{"type": "float"},
|
164
|
+
"MCP":{"type": "float"},
|
165
|
+
"HUMA":{"type": "float"},
|
166
|
+
"TCA":{"type": "float"},
|
167
|
+
"BAT":{"type": "float"},
|
168
|
+
"@timestamp":{"type":"date","format":"dateOptionalTime"}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}'
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
### MQTT message conversion
|
176
|
+
|
177
|
+
Sometimes, MQTT message conversion must be done in the network because the processing entities does not have the conversion function. In that case, the configuration similar to the above example can be used. The difference resides output configuration. In this example, since the same MQTT broker is used to upload converted data, topic rewriting function is used for separating messages before and after conversion.
|
178
|
+
|
179
|
+
![MQTT message conversion](https://github.com/toyokazu/fluent-plugin-mqtt-io/blob/master/images/mqtt_message_conversion.png "MQTT message conversion")
|
180
|
+
|
181
|
+
```
|
182
|
+
<source>
|
183
|
+
type mqtt
|
184
|
+
bind 192.168.1.100
|
185
|
+
port 1883
|
186
|
+
topic 'Libelium/+/+'
|
187
|
+
format xml
|
188
|
+
time_xpath '["cap:alert/cap:info/cap:onset", "text"]'
|
189
|
+
time_key '@timestamp'
|
190
|
+
attr_xpaths '[["cap:alert/cap:info/cap:parameter/cap:valueName", "text"]]'
|
191
|
+
value_xpaths '[["cap:alert/cap:info/cap:parameter/cap:value", "text"]]'
|
192
|
+
@label @MQTT_OUT
|
193
|
+
</source>
|
194
|
+
|
195
|
+
<label @MQTT_OUT>
|
196
|
+
<match **>
|
197
|
+
type mqtt
|
198
|
+
bind 192.168.1.100
|
199
|
+
port 1883
|
200
|
+
topic_rewrite_pattern '^([\w\/]+)$'
|
201
|
+
topic_rewrite_replacement '\1/rewritten'
|
202
|
+
</match>
|
203
|
+
</label>
|
204
|
+
|
205
|
+
```
|
206
|
+
|
207
|
+
|
208
|
+
### Sensor data uploads from tiny computers, e.g. Raspberry Pi, Edison, etc
|
209
|
+
|
210
|
+
MQTT output plugin can be used as the following. If you have tiny computers like Raspberry Pi equipped with sensors and their data are outputted as files, you can use fluent-plugin-mqtt-io for uploading those data.
|
211
|
+
|
212
|
+
![Sensor data uploads from tiny computers](https://github.com/toyokazu/fluent-plugin-mqtt-io/blob/master/images/sensor_data_uploads_from_tiny_computers.png "Sensor data uploads from tiny computers")
|
114
213
|
|
115
214
|
|
116
215
|
## Contributing
|
@@ -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-io"
|
7
|
-
spec.version = "0.0.
|
7
|
+
spec.version = "0.0.5"
|
8
8
|
spec.authors = ["Toyokazu Akiyama"]
|
9
9
|
spec.email = ["toyokazu@gmail.com"]
|
10
10
|
|
@@ -13,13 +13,15 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/toyokazu/fluent-plugin-mqtt-io"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.files = `git ls-files`.gsub(/images\/[\w\.]+\n/, "").split($/)
|
17
17
|
spec.bindir = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
+
spec.add_dependency 'fluentd', '>= 0.10.0'
|
23
|
+
spec.add_dependency "mqtt", "~> 0.3"
|
24
|
+
|
22
25
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "mqtt", "~> 0.3"
|
25
27
|
end
|
@@ -5,7 +5,7 @@ module Fluent
|
|
5
5
|
config_param :port, :integer, :default => 1883
|
6
6
|
config_param :bind, :string, :default => '127.0.0.1'
|
7
7
|
config_param :topic, :string, :default => '#'
|
8
|
-
config_param :format, :string, :default => '
|
8
|
+
config_param :format, :string, :default => 'json'
|
9
9
|
config_param :username, :string, :default => nil
|
10
10
|
config_param :password, :string, :default => nil
|
11
11
|
config_param :ssl, :bool, :default => nil
|
@@ -61,6 +61,10 @@ module Fluent
|
|
61
61
|
begin
|
62
62
|
topic.gsub!("/","\.")
|
63
63
|
@parser.parse(message) {|time, record|
|
64
|
+
if time.nil?
|
65
|
+
$log.debug "Since time_key field is nil, Fluent::Engine.now is used."
|
66
|
+
time = Fluent::Engine.now
|
67
|
+
end
|
64
68
|
$log.debug "#{topic}, #{time}, #{record}"
|
65
69
|
router.emit(topic, time, record)
|
66
70
|
}
|
metadata
CHANGED
@@ -1,57 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fluent-plugin-mqtt-io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toyokazu Akiyama
|
8
8
|
autorequire:
|
9
9
|
bindir: []
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: fluentd
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.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.10.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mqtt
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
33
|
+
version: '0.3'
|
34
|
+
type: :runtime
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '0.3'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version: '10
|
47
|
+
version: '1.10'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version: '10
|
54
|
+
version: '1.10'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
56
|
+
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - "~>"
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0
|
61
|
+
version: '10.0'
|
48
62
|
type: :development
|
49
63
|
prerelease: false
|
50
64
|
version_requirements: !ruby/object:Gem::Requirement
|
51
65
|
requirements:
|
52
66
|
- - "~>"
|
53
67
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0
|
68
|
+
version: '10.0'
|
55
69
|
description: fluentd input/output plugin for mqtt broker
|
56
70
|
email:
|
57
71
|
- toyokazu@gmail.com
|
@@ -98,3 +112,4 @@ specification_version: 4
|
|
98
112
|
summary: fluentd input/output plugin for mqtt broker
|
99
113
|
test_files:
|
100
114
|
- test/helper.rb
|
115
|
+
has_rdoc:
|