fluent-plugin-mysql-2 0.3.7
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 +7 -0
- data/.gitignore +18 -0
- data/.travis.yml +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +350 -0
- data/README_mysql.md +140 -0
- data/Rakefile +11 -0
- data/fluent-plugin-mysql.gemspec +24 -0
- data/lib/fluent/plugin/out_mysql.rb +126 -0
- data/lib/fluent/plugin/out_mysql_bulk.rb +234 -0
- data/test/helper.rb +29 -0
- data/test/plugin/test_out_mysql.rb +199 -0
- data/test/plugin/test_out_mysql_bulk.rb +360 -0
- metadata +167 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b08ae8a41a2889d1785aec8b5441392ffbcd249e5c38d78e257dd27e64465d2b
|
4
|
+
data.tar.gz: 6853750e68fffe251f60737fc2f8773201d976faafa71d13db0b9cec6eee87e2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68c4733f8c8ac2f1f585f09316c911611722f7b7c9486f658de414f04dc4be35a0bf17a6574048aa4334d58285c7f707a466680f421a9206ee9e54f4f9165818
|
7
|
+
data.tar.gz: 928424531e1218fc9be1c001d65faabc8d2fff84c3694b9fe9b35a4fce803682af344390c579b3016f41a2c5cb2edee6319e688439bf277c6f482a355da56691
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012- TAGOMORI Satoshi
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,350 @@
|
|
1
|
+
|
2
|
+
# fluent-plugin-mysql, a plugin for [Fluentd](http://fluentd.org) [](http://travis-ci.org/tagomoris/fluent-plugin-mysql)
|
3
|
+
|
4
|
+
fluent plugin mysql bulk insert is high performance and on duplicate key update respond.
|
5
|
+
|
6
|
+
## Note
|
7
|
+
fluent-plugin-mysql-bulk merged this repository.
|
8
|
+
|
9
|
+
[mysql plugin](README_mysql.md) is deprecated. You should use mysql_bulk.
|
10
|
+
|
11
|
+
v0.1.5 only supports fluentd-0.12.X and v0.2.0 only supports fluentd-0.14.X.
|
12
|
+
|
13
|
+
## Parameters
|
14
|
+
|
15
|
+
param|value
|
16
|
+
--------|------
|
17
|
+
host|database host(default: 127.0.0.1)
|
18
|
+
port|database port(default: 3306)
|
19
|
+
database|database name(require)
|
20
|
+
username|user(require)
|
21
|
+
password|password(default: blank)
|
22
|
+
sslkey|path to client key(default: nil)
|
23
|
+
sslcert|path to client cert(default: nil)
|
24
|
+
sslca|path to ca cert(default: nil)
|
25
|
+
sslcapath|path to ca certs(default: nil)
|
26
|
+
sslcipher|ssl cipher(default: nil)
|
27
|
+
sslverify|verify server certificate(default: nil)
|
28
|
+
column_names|bulk insert column (require)
|
29
|
+
key_names|value key names, ${time} is placeholder Time.at(time).strftime("%Y-%m-%d %H:%M:%S") (default : column_names)
|
30
|
+
json_key_names|Key names which store data as json, comma separator.
|
31
|
+
unixtimestamp_key_names|Key names which store data as datetime from unix time stamp
|
32
|
+
table|bulk insert table (require)
|
33
|
+
on_duplicate_key_update|on duplicate key update enable (true:false)
|
34
|
+
on_duplicate_update_keys|on duplicate key update column, comma separator
|
35
|
+
transaction_isolation_level|set transaction isolation level(default: nil)
|
36
|
+
|
37
|
+
## Configuration Example(bulk insert)
|
38
|
+
|
39
|
+
```
|
40
|
+
<match mysql.input>
|
41
|
+
@type mysql_bulk
|
42
|
+
host localhost
|
43
|
+
database test_app_development
|
44
|
+
username root
|
45
|
+
password hogehoge
|
46
|
+
column_names id,user_name,created_at,updated_at
|
47
|
+
table users
|
48
|
+
flush_interval 10s
|
49
|
+
</match>
|
50
|
+
```
|
51
|
+
|
52
|
+
Assume following input is coming:
|
53
|
+
|
54
|
+
```js
|
55
|
+
mysql.input: {"user_name":"toyama","created_at":"2014/01/03 21:35:15","updated_at":"2014/01/03 21:35:15","dummy":"hogehoge"}
|
56
|
+
mysql.input: {"user_name":"toyama2","created_at":"2014/01/03 21:35:21","updated_at":"2014/01/03 21:35:21","dummy":"hogehoge"}
|
57
|
+
mysql.input: {"user_name":"toyama3","created_at":"2014/01/03 21:35:27","updated_at":"2014/01/03 21:35:27","dummy":"hogehoge"}
|
58
|
+
```
|
59
|
+
|
60
|
+
then result becomes as below (indented):
|
61
|
+
|
62
|
+
```sql
|
63
|
+
+-----+-----------+---------------------+---------------------+
|
64
|
+
| id | user_name | created_at | updated_at |
|
65
|
+
+-----+-----------+---------------------+---------------------+
|
66
|
+
| 1 | toyama | 2014-01-03 21:35:15 | 2014-01-03 21:35:15 |
|
67
|
+
| 2 | toyama2 | 2014-01-03 21:35:21 | 2014-01-03 21:35:21 |
|
68
|
+
| 3 | toyama3 | 2014-01-03 21:35:27 | 2014-01-03 21:35:27 |
|
69
|
+
+-----+-----------+---------------------+---------------------+
|
70
|
+
```
|
71
|
+
|
72
|
+
running query
|
73
|
+
|
74
|
+
```sql
|
75
|
+
INSERT INTO users (id,user_name,created_at,updated_at) VALUES (NULL,'toyama','2014/01/03 21:35:15','2014/01/03 21:35:15'),(NULL,'toyama2','2014/01/03 21:35:21','2014/01/03 21:35:21')
|
76
|
+
```
|
77
|
+
|
78
|
+
## Configuration Example(bulk insert , if duplicate error record update)
|
79
|
+
|
80
|
+
```
|
81
|
+
<match mysql.input>
|
82
|
+
@type mysql_bulk
|
83
|
+
host localhost
|
84
|
+
database test_app_development
|
85
|
+
username root
|
86
|
+
password hogehoge
|
87
|
+
column_names id,user_name,created_at,updated_at
|
88
|
+
table users
|
89
|
+
on_duplicate_key_update true
|
90
|
+
on_duplicate_update_keys user_name,updated_at
|
91
|
+
flush_interval 60s
|
92
|
+
</match>
|
93
|
+
```
|
94
|
+
|
95
|
+
Assume following input is coming:
|
96
|
+
|
97
|
+
```js
|
98
|
+
mysql.input: {"id":"1" ,"user_name":"toyama7","created_at":"2014/01/03 21:58:03","updated_at":"2014/01/03 21:58:03"}
|
99
|
+
mysql.input: {"id":"2" ,"user_name":"toyama7","created_at":"2014/01/03 21:58:06","updated_at":"2014/01/03 21:58:06"}
|
100
|
+
mysql.input: {"id":"3" ,"user_name":"toyama7","created_at":"2014/01/03 21:58:08","updated_at":"2014/01/03 21:58:08"}
|
101
|
+
mysql.input: {"id":"10","user_name":"toyama7","created_at":"2014/01/03 21:58:18","updated_at":"2014/01/03 21:58:18"}
|
102
|
+
```
|
103
|
+
|
104
|
+
then result becomes as below (indented):
|
105
|
+
|
106
|
+
```sql
|
107
|
+
+-----+-----------+---------------------+---------------------+
|
108
|
+
| id | user_name | created_at | updated_at |
|
109
|
+
+-----+-----------+---------------------+---------------------+
|
110
|
+
| 1 | toyama7 | 2014-01-03 21:35:15 | 2014-01-03 21:58:03 |
|
111
|
+
| 2 | toyama7 | 2014-01-03 21:35:21 | 2014-01-03 21:58:06 |
|
112
|
+
| 3 | toyama7 | 2014-01-03 21:35:27 | 2014-01-03 21:58:08 |
|
113
|
+
| 10 | toyama7 | 2014-01-03 21:58:18 | 2014-01-03 21:58:18 |
|
114
|
+
+-----+-----------+---------------------+---------------------+
|
115
|
+
```
|
116
|
+
|
117
|
+
if duplicate id , update username and updated_at
|
118
|
+
|
119
|
+
|
120
|
+
## Configuration Example(bulk insert,fluentd key different column name)
|
121
|
+
|
122
|
+
```
|
123
|
+
<match mysql.input>
|
124
|
+
@type mysql_bulk
|
125
|
+
host localhost
|
126
|
+
database test_app_development
|
127
|
+
username root
|
128
|
+
password hogehoge
|
129
|
+
column_names id,user_name,created_at,updated_at
|
130
|
+
key_names id,user,created_date,updated_date
|
131
|
+
table users
|
132
|
+
flush_interval 10s
|
133
|
+
</match>
|
134
|
+
```
|
135
|
+
|
136
|
+
Assume following input is coming:
|
137
|
+
|
138
|
+
```js
|
139
|
+
mysql.input: {"user":"toyama","created_date":"2014/01/03 21:35:15","updated_date":"2014/01/03 21:35:15","dummy":"hogehoge"}
|
140
|
+
mysql.input: {"user":"toyama2","created_date":"2014/01/03 21:35:21","updated_date":"2014/01/03 21:35:21","dummy":"hogehoge"}
|
141
|
+
mysql.input: {"user":"toyama3","created_date":"2014/01/03 21:35:27","updated_date":"2014/01/03 21:35:27","dummy":"hogehoge"}
|
142
|
+
```
|
143
|
+
|
144
|
+
then result becomes as below (indented):
|
145
|
+
|
146
|
+
```sql
|
147
|
+
+-----+-----------+---------------------+---------------------+
|
148
|
+
| id | user_name | created_at | updated_at |
|
149
|
+
+-----+-----------+---------------------+---------------------+
|
150
|
+
| 1 | toyama | 2014-01-03 21:35:15 | 2014-01-03 21:35:15 |
|
151
|
+
| 2 | toyama2 | 2014-01-03 21:35:21 | 2014-01-03 21:35:21 |
|
152
|
+
| 3 | toyama3 | 2014-01-03 21:35:27 | 2014-01-03 21:35:27 |
|
153
|
+
+-----+-----------+---------------------+---------------------+
|
154
|
+
```
|
155
|
+
|
156
|
+
## Configuration Example(bulk insert, time complement)
|
157
|
+
|
158
|
+
```
|
159
|
+
<match mysql.input>
|
160
|
+
@type mysql_bulk
|
161
|
+
host localhost
|
162
|
+
database test_app_development
|
163
|
+
username root
|
164
|
+
password hogehoge
|
165
|
+
column_names id,user_name,created_at
|
166
|
+
key_names id,user,${time}
|
167
|
+
table users
|
168
|
+
flush_interval 10s
|
169
|
+
</match>
|
170
|
+
```
|
171
|
+
|
172
|
+
Assume following input is coming:
|
173
|
+
|
174
|
+
```js
|
175
|
+
2014-01-03 21:35:15+09:00: mysql.input: {"user":"toyama","dummy":"hogehoge"}
|
176
|
+
2014-01-03 21:35:21+09:00: mysql.input: {"user":"toyama2","dummy":"hogehoge"}
|
177
|
+
2014-01-03 21:35:27+09:00: mysql.input: {"user":"toyama3","dummy":"hogehoge"}
|
178
|
+
```
|
179
|
+
|
180
|
+
then `created_at` column is set from time attribute in a fluentd packet:
|
181
|
+
|
182
|
+
```sql
|
183
|
+
+-----+-----------+---------------------+
|
184
|
+
| id | user_name | created_at |
|
185
|
+
+-----+-----------+---------------------+
|
186
|
+
| 1 | toyama | 2014-01-03 21:35:15 |
|
187
|
+
| 2 | toyama2 | 2014-01-03 21:35:21 |
|
188
|
+
| 3 | toyama3 | 2014-01-03 21:35:27 |
|
189
|
+
+-----+-----------+---------------------+
|
190
|
+
```
|
191
|
+
|
192
|
+
## Configuration Example(bulk insert, time complement with specific timezone)
|
193
|
+
|
194
|
+
As described above, `${time}` placeholder sets time with `Time.at(time).strftime("%Y-%m-%d %H:%M:%S")`.
|
195
|
+
This handles the time with fluentd server default timezone.
|
196
|
+
If you want to use the specific timezone, you can use the include_time_key feature.
|
197
|
+
This is useful in case fluentd server and mysql have different timezone.
|
198
|
+
You can use various timezone format. See below.
|
199
|
+
http://docs.fluentd.org/articles/formatter-plugin-overview
|
200
|
+
|
201
|
+
```
|
202
|
+
<match mysql.input>
|
203
|
+
@type mysql_bulk
|
204
|
+
host localhost
|
205
|
+
database test_app_development
|
206
|
+
username root
|
207
|
+
password hogehoge
|
208
|
+
|
209
|
+
include_time_key yes
|
210
|
+
timezone +00
|
211
|
+
time_format %Y-%m-%d %H:%M:%S
|
212
|
+
time_key created_at
|
213
|
+
|
214
|
+
column_names id,user_name,created_at
|
215
|
+
key_names id,user,created_at
|
216
|
+
table users
|
217
|
+
flush_interval 10s
|
218
|
+
</match>
|
219
|
+
```
|
220
|
+
|
221
|
+
Assume following input is coming(fluentd server is using JST +09 timezone):
|
222
|
+
|
223
|
+
```js
|
224
|
+
2014-01-03 21:35:15+09:00: mysql.input: {"user":"toyama","dummy":"hogehoge"}
|
225
|
+
2014-01-03 21:35:21+09:00: mysql.input: {"user":"toyama2","dummy":"hogehoge"}
|
226
|
+
2014-01-03 21:35:27+09:00: mysql.input: {"user":"toyama3","dummy":"hogehoge"}
|
227
|
+
```
|
228
|
+
|
229
|
+
then `created_at` column is set from time attribute in a fluentd packet with timezone converted to +00 UTC:
|
230
|
+
|
231
|
+
```sql
|
232
|
+
+-----+-----------+---------------------+
|
233
|
+
| id | user_name | created_at |
|
234
|
+
+-----+-----------+---------------------+
|
235
|
+
| 1 | toyama | 2014-01-03 12:35:15 |
|
236
|
+
| 2 | toyama2 | 2014-01-03 12:35:21 |
|
237
|
+
| 3 | toyama3 | 2014-01-03 12:35:27 |
|
238
|
+
+-----+-----------+---------------------+
|
239
|
+
```
|
240
|
+
|
241
|
+
## Configuration Example(bulk insert with tag placeholder for table name)
|
242
|
+
|
243
|
+
This description is for v0.14.X users.
|
244
|
+
|
245
|
+
```
|
246
|
+
<match mysql.input>
|
247
|
+
@type mysql_bulk
|
248
|
+
host localhost
|
249
|
+
database test_app_development
|
250
|
+
username root
|
251
|
+
password hogehoge
|
252
|
+
column_names id,user_name,created_at
|
253
|
+
key_names id,user,${time}
|
254
|
+
table users_${tag}
|
255
|
+
<buffer tag>
|
256
|
+
@type memory
|
257
|
+
flush_interval 60s
|
258
|
+
</buffer>
|
259
|
+
</match>
|
260
|
+
```
|
261
|
+
|
262
|
+
Assume following input is coming:
|
263
|
+
|
264
|
+
```js
|
265
|
+
2016-09-26 18:42:13+09:00: mysql.input: {"user":"toyama","dummy":"hogehoge"}
|
266
|
+
2016-09-26 18:42:16+09:00: mysql.input: {"user":"toyama2","dummy":"hogehoge"}
|
267
|
+
2016-09-26 18:42:19+09:00: mysql.input: {"user":"toyama3","dummy":"hogehoge"}
|
268
|
+
```
|
269
|
+
|
270
|
+
then `created_at` column is set from time attribute in a fluentd packet:
|
271
|
+
|
272
|
+
```sql
|
273
|
+
mysql> select * from users_mysql_input;
|
274
|
+
+----+-----------+---------------------+
|
275
|
+
| id | user_name | created_at |
|
276
|
+
+----+-----------+---------------------+
|
277
|
+
| 1 | toyama | 2016-09-26 18:42:13 |
|
278
|
+
| 2 | toyama2 | 2016-09-26 18:42:16 |
|
279
|
+
| 3 | toyama3 | 2016-09-26 18:42:19 |
|
280
|
+
+----+-----------+---------------------+
|
281
|
+
3 rows in set (0.00 sec)
|
282
|
+
```
|
283
|
+
|
284
|
+
## Configuration Example(bulk insert with time format placeholder for table name)
|
285
|
+
|
286
|
+
This description is for v0.14.X users.
|
287
|
+
|
288
|
+
```
|
289
|
+
<match mysql.input>
|
290
|
+
@type mysql_bulk
|
291
|
+
host localhost
|
292
|
+
database test_app_development
|
293
|
+
username root
|
294
|
+
password hogehoge
|
295
|
+
column_names id,user_name,created_at
|
296
|
+
key_names id,user,${time}
|
297
|
+
table users_%Y%m%d
|
298
|
+
<buffer time>
|
299
|
+
@type memory
|
300
|
+
timekey 60s
|
301
|
+
timekey_wait 60s
|
302
|
+
</buffer>
|
303
|
+
</match>
|
304
|
+
```
|
305
|
+
|
306
|
+
Assume following input is coming:
|
307
|
+
|
308
|
+
```js
|
309
|
+
2016-09-26 18:37:06+09:00: mysql.input: {"user":"toyama","dummy":"hogehoge"}
|
310
|
+
2016-09-26 18:37:08+09:00: mysql.input: {"user":"toyama2","dummy":"hogehoge"}
|
311
|
+
2016-09-26 18:37:11+09:00: mysql.input: {"user":"toyama3","dummy":"hogehoge"}
|
312
|
+
```
|
313
|
+
|
314
|
+
then `created_at` column is set from time attribute in a fluentd packet:
|
315
|
+
|
316
|
+
```sql
|
317
|
+
mysql> select * from users_20160926;
|
318
|
+
+----+-----------+---------------------+
|
319
|
+
| id | user_name | created_at |
|
320
|
+
+----+-----------+---------------------+
|
321
|
+
| 1 | toyama | 2016-09-26 18:37:06 |
|
322
|
+
| 2 | toyama2 | 2016-09-26 18:37:08 |
|
323
|
+
| 3 | toyama3 | 2016-09-26 18:37:11 |
|
324
|
+
+----+-----------+---------------------+
|
325
|
+
3 rows in set (0.00 sec)
|
326
|
+
```
|
327
|
+
|
328
|
+
## spec
|
329
|
+
|
330
|
+
```
|
331
|
+
bundle install
|
332
|
+
rake test
|
333
|
+
```
|
334
|
+
|
335
|
+
## todo
|
336
|
+
|
337
|
+
divide bulk insert(exsample 1000 per)
|
338
|
+
|
339
|
+
|
340
|
+
## Contributing
|
341
|
+
|
342
|
+
1. Fork it
|
343
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
344
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
345
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
346
|
+
5. Create new [Pull Request](../../pull/new/master)
|
347
|
+
|
348
|
+
## Copyright
|
349
|
+
|
350
|
+
Copyright (c) 2016 Hiroshi Toyama. See [LICENSE](LICENSE.txt) for details.
|
data/README_mysql.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# fluent-plugin-mysql
|
2
|
+
|
3
|
+
## Component
|
4
|
+
|
5
|
+
### MysqlOutput
|
6
|
+
|
7
|
+
[Fluentd](http://fluentd.org) plugin to store mysql tables over SQL, to each columns per values, or to single column as json.
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
### MysqlOutput
|
12
|
+
|
13
|
+
MysqlOutput needs MySQL server's host/port/database/username/password, and INSERT format as SQL, or as table name and columns.
|
14
|
+
|
15
|
+
<match output.by.sql.*>
|
16
|
+
type mysql
|
17
|
+
host master.db.service.local
|
18
|
+
# port 3306 # default
|
19
|
+
database application_logs
|
20
|
+
username myuser
|
21
|
+
password mypass
|
22
|
+
key_names status,bytes,vhost,path,rhost,agent,referer
|
23
|
+
sql INSERT INTO accesslog (status,bytes,vhost,path,rhost,agent,referer) VALUES (?,?,?,?,?,?,?)
|
24
|
+
flush_interval 5s
|
25
|
+
</match>
|
26
|
+
|
27
|
+
<match output.by.names.*>
|
28
|
+
type mysql
|
29
|
+
host master.db.service.local
|
30
|
+
database application_logs
|
31
|
+
username myuser
|
32
|
+
password mypass
|
33
|
+
key_names status,bytes,vhost,path,rhost,agent,referer
|
34
|
+
table accesslog
|
35
|
+
# 'columns' names order must be same with 'key_names'
|
36
|
+
columns status,bytes,vhost,path,rhost,agent,referer
|
37
|
+
flush_interval 5s
|
38
|
+
</match>
|
39
|
+
|
40
|
+
Or, insert json into single column.
|
41
|
+
|
42
|
+
<match output.as.json.*>
|
43
|
+
type mysql
|
44
|
+
host master.db.service.local
|
45
|
+
database application_logs
|
46
|
+
username root
|
47
|
+
table accesslog
|
48
|
+
columns jsondata
|
49
|
+
format json
|
50
|
+
flush_interval 5s
|
51
|
+
</match>
|
52
|
+
|
53
|
+
To include time/tag into output, use `include_time_key` and `include_tag_key`, like this:
|
54
|
+
|
55
|
+
<match output.with.tag.and.time.*>
|
56
|
+
type mysql
|
57
|
+
host my.mysql.local
|
58
|
+
database anydatabase
|
59
|
+
username yourusername
|
60
|
+
password secret
|
61
|
+
|
62
|
+
include_time_key yes
|
63
|
+
### default `time_format` is ISO-8601
|
64
|
+
# time_format %Y%m%d-%H%M%S
|
65
|
+
### default `time_key` is 'time'
|
66
|
+
# time_key timekey
|
67
|
+
|
68
|
+
include_tag_key yes
|
69
|
+
### default `tag_key` is 'tag'
|
70
|
+
# tag_key tagkey
|
71
|
+
|
72
|
+
table anydata
|
73
|
+
key_names time,tag,field1,field2,field3,field4
|
74
|
+
sql INSERT INTO baz (coltime,coltag,col1,col2,col3,col4) VALUES (?,?,?,?,?,?)
|
75
|
+
</match>
|
76
|
+
|
77
|
+
Or, for json:
|
78
|
+
|
79
|
+
<match output.with.tag.and.time.as.json.*>
|
80
|
+
type mysql
|
81
|
+
host database.local
|
82
|
+
database foo
|
83
|
+
username root
|
84
|
+
|
85
|
+
include_time_key yes
|
86
|
+
utc # with UTC timezone output (default: localtime)
|
87
|
+
time_format %Y%m%d-%H%M%S
|
88
|
+
time_key timeattr
|
89
|
+
|
90
|
+
include_tag_key yes
|
91
|
+
tag_key tagattr
|
92
|
+
table accesslog
|
93
|
+
columns jsondata
|
94
|
+
format json
|
95
|
+
</match>
|
96
|
+
#=> inserted json data into column 'jsondata' with addtional attribute 'timeattr' and 'tagattr'
|
97
|
+
|
98
|
+
### JsonPath format
|
99
|
+
|
100
|
+
You can use [JsonPath](http://goessner.net/articles/JsonPath/) selectors as key_names, such as:
|
101
|
+
|
102
|
+
<match output.with.jsonpath.format.*>
|
103
|
+
type mysql
|
104
|
+
host database.local
|
105
|
+
database foo
|
106
|
+
username bar
|
107
|
+
|
108
|
+
include_time_key yes
|
109
|
+
utc
|
110
|
+
include_tag_key yes
|
111
|
+
table baz
|
112
|
+
|
113
|
+
format jsonpath
|
114
|
+
key_names time, tag, id, data.name, tags[0]
|
115
|
+
sql INSERT INTO baz (coltime,coltag,id,name,tag1) VALUES (?,?,?,?,?)
|
116
|
+
</match>
|
117
|
+
|
118
|
+
Which for a record like:
|
119
|
+
|
120
|
+
`{ 'id' => 15, 'data'=> {'name' => 'jsonpath' }, 'tags' => ['unit', 'simple'] }`
|
121
|
+
|
122
|
+
will generate the following insert values:
|
123
|
+
|
124
|
+
`('2012-12-17T01:23:45Z','test',15,'jsonpath','unit')`
|
125
|
+
|
126
|
+
## Prerequisites
|
127
|
+
|
128
|
+
`fluent-plugin-mysql` uses `mysql2` gem, and `mysql2` links against `libmysqlclient`. See [Installing](https://github.com/brianmario/mysql2#installing) for its installation.
|
129
|
+
|
130
|
+
## TODO
|
131
|
+
|
132
|
+
* implement 'tag_mapped'
|
133
|
+
* dynamic tag based table selection
|
134
|
+
|
135
|
+
## Copyright
|
136
|
+
|
137
|
+
* Copyright
|
138
|
+
* Copyright(C) 2016- TAGOMORI Satoshi (tagomoris)
|
139
|
+
* License
|
140
|
+
* Apache License, Version 2.0
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
Gem::Specification.new do |gem|
|
3
|
+
gem.name = "fluent-plugin-mysql-2"
|
4
|
+
gem.version = "0.3.7"
|
5
|
+
gem.authors = ["TAGOMORI Satoshi", "Toyama Hiroshi", "Alex Scarborough"]
|
6
|
+
gem.email = ["tagomoris@gmail.com", "toyama0919@gmail.com", "alex@teak.io"]
|
7
|
+
gem.description = %q{fluent plugin to insert mysql as json(single column) or insert statement}
|
8
|
+
gem.summary = %q{fluent plugin to insert mysql}
|
9
|
+
gem.homepage = "https://github.com/GoCarrot/fluent-plugin-mysql"
|
10
|
+
gem.license = "Apache-2.0"
|
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_runtime_dependency "fluentd", ['>= 0.14.8', '< 2']
|
18
|
+
gem.add_runtime_dependency "mysql2-cs-bind"
|
19
|
+
gem.add_runtime_dependency "jsonpath"
|
20
|
+
gem.add_runtime_dependency "oj"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "test-unit"
|
23
|
+
gem.add_development_dependency "timecop", "~> 0.8.0"
|
24
|
+
end
|