際際滷

際際滷Share a Scribd company logo
Fluentd with MySQL
V1.0
煙殊 : 2015.08
   :   蟲
1
2
Index
1. Intro
2. Install
3. Test
 MySQL slowquery logging
 MySQL process list logging
 Game Log Data Collect
 Log Server 蟲豢
4. QnA
3
Intro
4
Intro
Fluentd is a fully free and fully open-source log collector that instantly enables you to have a Log Everything
architecture with 125+ types of systems.
http://docs.fluentd.org
5
Intro
Reference : http://blog.seulgi.kim/2014/04/fluentd-pluggable-log-collector.html
6
Intro
Input plugin
Input plugin  碁襦覿 企欧碁ゼ 覦り碓 碁 殊 曙伎 企欧碁ゼ 襷れ 譯朱  .
fluentd 伎語 るジ log aggregatorれ 螳 豬渚 覿覿朱, 覦襦 襷覃 fluentd 豕螻 レ  覿覿
願鍵 .
fluentd 蟆曙磯 企 襷 pluginれ 襷れ伎 伎  覿覿 plugin 谿場  螻,
谿場 覈詩朱 所 plugin 襷  .
Reference : http://blog.seulgi.kim/2014/04/fluentd-pluggable-log-collector.html
7
Intro
Output plugin
Output plugin  曙 企欧碁ゼ 碁 レ  碁 觜る   
レ input plugin  牛伎 れ伎 engine 蟇一 buffer plugin 蟇一讌 螻 output plugin朱 螳.
buffer engine  蟆  output plugin 企 .
覃, output 譬襯 磯殊 buffer螳 讌  蟆曙郁 , buffer  覿襯 output plugin 蟆一伎 蠍 覓語企.
buffer plugin  讌  output plugin non-buffered output plugin 企手 覿襯企,  螳 out_null螻 out_stdout
plugin企. out_null 蟆曙 れ伎る レ 覿 覯襴 plugin願, out_stdout れ伎る レ 貉るЖ 谿曙 譯朱 plugin企.
 るジ 蟆曙磯 out_copy .  plugin  fluentd襦 れ伎 event襯 2螳 伎 output朱 覲企  一碁.
磯殊 れ るジ output plugin 螻,  output plugin  buffer襯 蠍 覓語 豌伎朱 buffer襯 伎 伎螳 .
覯蟆 buffer plugin  pluginれ buffered output plugin企手 覿襯企  譴 朱 time sliced output plugin企手
覿襴磯. time sliced output plugin buffer襯 讌襷, chunk key襦 tag螳  螳 る 蟆襷 るゴ.
8
Intro
Buffer plugin
1. Output  朱 企慨企 蠍磯
log aggregator れ螳朱 襦蠏碁ゼ 覈譯殊襷, 覈 襦蠏碁ゼ 覦襦 覦襦 output 朱 覲企 伎 . 蠏碁 fluentd 襯 觜襦 覿覿 aggregator 覯 殊 襦蠏碁ゼ
覈り 豌襴襦 伎. fluentd  襯 chunk手 覿襯企, chunk log tag 覲襦 覿襯 ル.
output plugin 一 chunk襯 queue 讌企l 螻 れ伎る log襯 chunk . 蠏碁り chunk 蠍郁 殊 伎 貉れ蟇磯, chunk螳 蠍伎 殊 螳 伎 讌覃
queue れ願. chunk tag襯 key襦 覩襦 buffer れ願讌 螻  chunk螳  螳 伎  .
queue 蠍磯ゼ 殊 伎 れ一 蠍  queue chunk襯 讌企l , queue chunk襯 1螳 觜殊 output朱 企慨碁.
2. Collector 覯 レ log  豕 蠍磯
Buffer 襯 り 企 覃覈襴螳 覓危 蟆 覩襦 覯 る 覓語 朱 覯れ 一危郁 蠍郁 . fluentd  襯 螻 蠏碁  覃 覯襴 蟆
豈朱 手 . 讀, output朱 螳  data螳 螳讌 覈詩  殊 螳 讌  れ 覃, 蠏碁 ろる, 蠍磯る碁 螳 2覦磯  蠍磯るΜ螻
れ 蠍磯ゼ 覦覲牛. 殊 襯 蠍磯るる 覲企企 蟆 ろ覃  一危磯 れ朱 覲企伎讌 螻 覯れ. (螳: retry_wait, : retry_limit襦 れ)
fluentd 豌願 覓語螳 蟆 蟶殊 蟆曙磯 , 願 buffer plugin朱  譬襯襯  願屋  .
蠍磯蓋朱 fluentd螳 buffer  蟆 buf_memory 朱 plugin朱 chunk襯 memory 蠍磯 plugin 企. 讌襷 覯螳 譯曙 伎  覲伎ロ螻 矩る
buf_file plugin 伎覃 . buf_file plugin 覃 chunk 伎 file 覲願 譯手鍵 覓語 覯螳 れ 貅讌  file 曙伎 buffer 伎 覲糾規伎.
file 磯 襷 螳 れ讌襷, 煙 讀螳蠍磯 螻,    buffer 蠍磯 貉れ.
9
Index
1. Intro
2. Install
3. Test
 MySQL slowquery logging
 MySQL process list logging
 Game Log Data Collect
 Log Server 蟲豢
4. QnA
10
Intro
Fluentd nested plugin
URL(input) : http://docs.fluentd.org/articles/input-plugin-overview
URL(output) : http://docs.fluentd.org/articles/output-plugin-overview
11
Install
"讌(Client)" 覯襦  Fluentd れ
http://docs.fluentd.org/v0.12/categories/installation
# sudo su -
cd /usr1/program/
curl -L https://td-toolbelt.herokuapp.com/sh/install-redhat-td-agent2.sh | sh
# /etc/init.d/td-agent start
/etc/init.d/td-agent status
/etc/init.d/td-agent restart
/etc/init.d/td-agent stop
# cat /etc/td-agent/td-agent.conf
# curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test
tail -f /var/log/td-agent/td-agent.log
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
12
Index
1. Intro
2. Install
3. Test
 MySQL slowquery logging
 MySQL process list logging
 Game Log Data Collect
 Log Server 蟲豢
4. QnA
13
Step.1 讌 覯襦  Fluentd plugin れ
https://github.com/yuku-t/fluent-plugin-mysqlslowquery
https://github.com/tagomoris/fluent-plugin-mysql
https://github.com/toyama0919/fluent-plugin-mysql-bulk
# yum -y install ruby-rdoc ruby-devel rubygems
find / -name fluent-gem
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysqlslowquery
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysql-bulk
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.1 MySQL slowquery logging
14
Test.1 MySQL slowquery logging
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.2 讌蠍(Collector) 覯襦  Log 企 
$ mysql -u root -p
use test;
drop table if exists test.t_mysql_slow;
create table test.t_mysql_slow (
log_date datetime default current_timestamp
, user varchar(100)
, host varchar(100)
, host_ip varchar(20)
, query_time decimal(20,10)
, lock_time decimal(20,10)
, rows_sent bigint
, rows_examined bigint
, sql_text varchar(10000)
);
15
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.3 讌(DB) 覯襦  td-agent.conf れ
$ sudo vi /etc/td-agent/td-agent.conf


<source>
type mysql_slow_query
path /data/mysql/ADMIN/slowquery.log
tag ec-ldb-m2.mysql_slow
</source>
<match ec-ldb-m2.mysql_slow>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host ec-ldb-m2
port 19336
database test
username root
password testpasswd12#$
column_names user,host,host_ip,query_time,lock_time,rows_sent,rows_examined,sql_text
key_names user,host,host_ip,query_time,lock_time,rows_sent,rows_examined,sql_text
table t_mysql_slow
flush_interval 5s
</store>
</match>
Test.1 MySQL slowquery logging
16
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.4 td-agent  覦 覿貎朱Μ 
$ sudo /etc/init.d/td-agent stop
sudo /etc/init.d/td-agent start
tail -f /var/log/td-agent/td-agent.log
Test.1 MySQL slowquery logging
$ mysql -u root -p
select sleep(1);
select sleep(1);
17
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.5 讌蠍(Collector) 覯 襦蠏 
$ mysql -u root p
select sleep(1);
select sleep(1);
Test.1 MySQL slowquery logging
$ mysql -u root -p
select * from t_mysql_slow;
18
Index
1. Intro
2. Install
3. Test
 MySQL slowquery logging
 MySQL process list logging
 Game Log Data Collect
 Log Server 蟲豢
4. QnA
19
Step.1 讌 覯襦  Fluentd plugin れ
https://github.com/y-ken/fluent-plugin-mysql-query
https://github.com/shunwen/fluent-plugin-rename-key
# yum -y install ruby-rdoc ruby-devel rubygems
find / -name fluent-gem
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysql-query
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-rename-key
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.2 MySQL process list logging
20
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.2 MySQL process list logging
Step.2 讌蠍(Collector) 覯襦  Log 企 
$ mysql -u root -p
use test;
drop table if exists test.t_mysql_process;
create table test.t_mysql_process (
log_date datetime default current_timestamp
, hostname varchar(100)
, id bigint
, user varchar(100)
, host varchar(100)
, db varchar(64)
, command varchar(50)
, duration_time bigint
, state varchar(4000)
, info varchar(10000)
);
21
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.2 MySQL process list logging
Step.3 讌(DB) 覯襦  td-agent.conf れ
$ sudo vi /etc/td-agent/td-agent.conf


<source>
type mysql_query
host ec-ldb-s2
port 19336
database test
username root
password 433dlxjsjf12!@!
interval 1m
tag ec-ldb-s2.processlist
query show full processlist;
record_hostname yes
nest_result no
nest_key data
#row_count yes
#row_count_key row_count
</source>
<match ec-ldb-s2.processlist>
type rename_key
remove_tag_prefix ec-ldb-s2.
append_tag ec-ldb-s2
rename_rule1 Time duration_time
</match>
<match processlist.ec-ldb-s2>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host ec-ldb-m2
port 19336
database test
username root
password testpasswd12#$
column_names hostname,Id,User,Host,db,Command,State,Info,duration_time
key_names hostname,Id,User,Host,db,Command,State,Info,duration_time
table t_mysql_process
flush_interval 5s
</store>
</match>
22
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.2 MySQL process list logging
Step.4 td-agent 
$ sudo /etc/init.d/td-agent stop
sudo /etc/init.d/td-agent start
tail -f /var/log/td-agent/td-agent.log
23
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.2 MySQL process list logging
Step.5 讌蠍(Collector) 覯 襦蠏 
$ mysql -u root p
use test;
select * from t_mysql_process;
24
Index
1. Intro
2. Install
3. Test
 MySQL slowquery logging
 MySQL process list logging
 Game Log Data Collect
 Log Server 蟲豢
4. QnA
25
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.1 讌蠍(Collector) 覯襦  Log 企 
$ mysql -u root -p
use test;
drop table if exists test.log_game_play;
create table test.log_game_play (
log_date datetime default current_timestamp
, useridx bigint
, play_time bigint
, char_type varchar(1)
, result varchar(1)
);
alter table log_game_play add primary key(log_date,useridx);
Test.3 Game Log Collect
26
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.2 讌 覯襦  Log 企  覦 一危 
$ mysql -u root -p
use test;
drop table if exists test.log_game_play;
create table test.log_game_play (
log_date datetime default current_timestamp
, useridx bigint
, play_time bigint
, char_type varchar(1)
, result varchar(1)
);
alter table log_game_play add primary key(log_date,useridx);
Test.3 Game Log Collect
set @i=0;
insert ignore into test.log_game_play
select date_sub(now(), interval @i:=@i+1 minute) as log_date
, @i
, rand()*10000
, mod(@i,10)
, mod(@i,3)
from mysql.proc
limit 100;
select date_format(log_date, '%Y%m%d%h') as dt, count(*) from
test.log_game_play group by date_format(log_date, '%Y%m%d%h');
select * from test.log_game_play where log_date between date_sub(now(),
interval 10 minute) and now();
27
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.3 讌(DB) 覯襦  td-agent.conf れ
$ sudo vi /etc/td-agent/td-agent.conf


<source>
type mysql_query
host ec-ldb-s2
port 19336
database test
username root
password 433dlxjsjf12!@!
interval 10s
tag ec-ldb-s2.log_game_play
query select * from test.log_game_play where log_date
between date_sub(now(), interval 10 minute) and now();
record_hostname yes
nest_result no
nest_key data
#row_count yes
#row_count_key row_count
</source>
<match ec-ldb-s2.log_game_play>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host ec-ldb-m2
port 19336
database test
username root
password 433dlxjsjf12!@!
column_names log_date,useridx,play_time,char_type,result
key_names log_date,useridx,play_time,char_type,result
table log_game_play
on_duplicate_key_update true
on_duplicate_update_keys log_date,useridx
flush_interval 15s
</store>
</match>
Test.3 Game Log Collect
28
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.4 td-agent 
$ sudo /etc/init.d/td-agent stop
sudo /etc/init.d/td-agent start
tail -f /var/log/td-agent/td-agent.log
Test.3 Game Log Collect
29
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.5 讌蠍(Collector) 覯 襦蠏 
$ mysql -u root p
use test;
select * from test.log_game_play;
Test.3 Game Log Collect
30
Index
1. Intro
2. Install
3. Test
 MySQL slowquery logging
 MySQL process list logging
 Game Log Data Collect
 Log Server 蟲豢
4. QnA
31
Step.1 讌 覯襦  Fluentd plugin れ
https://github.com/tagomoris/fluent-plugin-mysql
# yum -y install ruby-rdoc ruby-devel rubygems
find / -name fluent-gem
/opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysql
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Test.4 Log Server 蟲豢
Client
Client
Client
Server
Server
HAProxy(L4)
32
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.2 讌蠍(Collector) 覯襦  Log 企 
$ mysql -u root -p
use test;
drop table if exists test.t_log_connect;
create table test.t_log_connect (
log_date datetime default current_timestamp
, jsondata text
);
drop table if exists test.t_log_money;
create table test.t_log_money (
log_date datetime default current_timestamp
, jsondata text
);
Test.4 Log Server 蟲豢
33
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.3 讌(DB) 覯襦  td-agent.conf れ
$ sudo vi /etc/td-agent/td-agent.conf


<source>
type http
port 8888
body_size_limit 1mb
keepalive_timeout 10s
</source>
<match ec-ldb-s2.t_log_connect>
type copy
<store>
type stdout
</store>
<store>
type mysql
host ec-ldb-m2
port 19336
database test
username root
password testpasswd12#$
table t_log_connect
columns jsondata
format json
flush_interval 5s
</store>
</match>
<match ec-ldb-s2.t_log_money>
type copy
<store>
type stdout
</store>
<store>
type mysql
host ec-ldb-m2
port 19336
database test
username root
password testpasswd12#$
table t_log_money
columns jsondata
format json
flush_interval 5s
</store>
</match>
Test.4 Log Server 蟲豢
34
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.4 td-agent 
$ sudo /etc/init.d/td-agent stop
sudo /etc/init.d/td-agent start
-- 襦蠏 覦
curl -X POST -d 'json={"ver":"1.0","action":"login","user":1}' http://localhost:8888/ec-ldb-s2.t_log_connect
curl -X POST -d 'json={"ver":"1.0","action":"login","user":1}' http://localhost:8888/ec-ldb-s2.t_log_money
tail -f /var/log/td-agent/td-agent.log
Test.4 Log Server 蟲豢
35
Collector
[ec-ldb-m2]
Service DB
[ec-ldb-s2]
Step.5 讌蠍(Collector) 覯 襦蠏 
$ mysql -u root p
use test;
select count(*) from test.t_log_money;
select count(*) from test.t_log_connect;
Test.4 Log Server 蟲豢
36
Test.0 覦
37
Test.0 覦
BackupDB
Service.1
Service.2
Service.3
1. federated engine or Export/Import  伎
襷れ 3螳 伎 Log Data 襯 覦煙覦  
1. 轟蠍郁 伎 螻手碓 一危磯ゼ 10覿襦 覦煙
覦朱 覿  覦一 蟇
2. 譯殊 讌 一危一 伎 ETL  豌危 
讌 蟾?
Fluentd Agent Pool
38
Reference
RubyConf 2014 - Build the Unified Logging Layer with Fluentd and Ruby by Kiyoto Tamura
https://www.youtube.com/watch?v=sIVGsQgMHIo
39

More Related Content

Fluentd with MySQL

  • 1. Fluentd with MySQL V1.0 煙殊 : 2015.08 : 蟲 1
  • 2. 2 Index 1. Intro 2. Install 3. Test MySQL slowquery logging MySQL process list logging Game Log Data Collect Log Server 蟲豢 4. QnA
  • 4. 4 Intro Fluentd is a fully free and fully open-source log collector that instantly enables you to have a Log Everything architecture with 125+ types of systems. http://docs.fluentd.org
  • 6. 6 Intro Input plugin Input plugin 碁襦覿 企欧碁ゼ 覦り碓 碁 殊 曙伎 企欧碁ゼ 襷れ 譯朱 . fluentd 伎語 るジ log aggregatorれ 螳 豬渚 覿覿朱, 覦襦 襷覃 fluentd 豕螻 レ 覿覿 願鍵 . fluentd 蟆曙磯 企 襷 pluginれ 襷れ伎 伎 覿覿 plugin 谿場 螻, 谿場 覈詩朱 所 plugin 襷 . Reference : http://blog.seulgi.kim/2014/04/fluentd-pluggable-log-collector.html
  • 7. 7 Intro Output plugin Output plugin 曙 企欧碁ゼ 碁 レ 碁 觜る レ input plugin 牛伎 れ伎 engine 蟇一 buffer plugin 蟇一讌 螻 output plugin朱 螳. buffer engine 蟆 output plugin 企 . 覃, output 譬襯 磯殊 buffer螳 讌 蟆曙郁 , buffer 覿襯 output plugin 蟆一伎 蠍 覓語企. buffer plugin 讌 output plugin non-buffered output plugin 企手 覿襯企, 螳 out_null螻 out_stdout plugin企. out_null 蟆曙 れ伎る レ 覿 覯襴 plugin願, out_stdout れ伎る レ 貉るЖ 谿曙 譯朱 plugin企. るジ 蟆曙磯 out_copy . plugin fluentd襦 れ伎 event襯 2螳 伎 output朱 覲企 一碁. 磯殊 れ るジ output plugin 螻, output plugin buffer襯 蠍 覓語 豌伎朱 buffer襯 伎 伎螳 . 覯蟆 buffer plugin pluginれ buffered output plugin企手 覿襯企 譴 朱 time sliced output plugin企手 覿襴磯. time sliced output plugin buffer襯 讌襷, chunk key襦 tag螳 螳 る 蟆襷 るゴ.
  • 8. 8 Intro Buffer plugin 1. Output 朱 企慨企 蠍磯 log aggregator れ螳朱 襦蠏碁ゼ 覈譯殊襷, 覈 襦蠏碁ゼ 覦襦 覦襦 output 朱 覲企 伎 . 蠏碁 fluentd 襯 觜襦 覿覿 aggregator 覯 殊 襦蠏碁ゼ 覈り 豌襴襦 伎. fluentd 襯 chunk手 覿襯企, chunk log tag 覲襦 覿襯 ル. output plugin 一 chunk襯 queue 讌企l 螻 れ伎る log襯 chunk . 蠏碁り chunk 蠍郁 殊 伎 貉れ蟇磯, chunk螳 蠍伎 殊 螳 伎 讌覃 queue れ願. chunk tag襯 key襦 覩襦 buffer れ願讌 螻 chunk螳 螳 伎 . queue 蠍磯ゼ 殊 伎 れ一 蠍 queue chunk襯 讌企l , queue chunk襯 1螳 觜殊 output朱 企慨碁. 2. Collector 覯 レ log 豕 蠍磯 Buffer 襯 り 企 覃覈襴螳 覓危 蟆 覩襦 覯 る 覓語 朱 覯れ 一危郁 蠍郁 . fluentd 襯 螻 蠏碁 覃 覯襴 蟆 豈朱 手 . 讀, output朱 螳 data螳 螳讌 覈詩 殊 螳 讌 れ 覃, 蠏碁 ろる, 蠍磯る碁 螳 2覦磯 蠍磯るΜ螻 れ 蠍磯ゼ 覦覲牛. 殊 襯 蠍磯るる 覲企企 蟆 ろ覃 一危磯 れ朱 覲企伎讌 螻 覯れ. (螳: retry_wait, : retry_limit襦 れ) fluentd 豌願 覓語螳 蟆 蟶殊 蟆曙磯 , 願 buffer plugin朱 譬襯襯 願屋 . 蠍磯蓋朱 fluentd螳 buffer 蟆 buf_memory 朱 plugin朱 chunk襯 memory 蠍磯 plugin 企. 讌襷 覯螳 譯曙 伎 覲伎ロ螻 矩る buf_file plugin 伎覃 . buf_file plugin 覃 chunk 伎 file 覲願 譯手鍵 覓語 覯螳 れ 貅讌 file 曙伎 buffer 伎 覲糾規伎. file 磯 襷 螳 れ讌襷, 煙 讀螳蠍磯 螻, buffer 蠍磯 貉れ.
  • 9. 9 Index 1. Intro 2. Install 3. Test MySQL slowquery logging MySQL process list logging Game Log Data Collect Log Server 蟲豢 4. QnA
  • 10. 10 Intro Fluentd nested plugin URL(input) : http://docs.fluentd.org/articles/input-plugin-overview URL(output) : http://docs.fluentd.org/articles/output-plugin-overview
  • 11. 11 Install "讌(Client)" 覯襦 Fluentd れ http://docs.fluentd.org/v0.12/categories/installation # sudo su - cd /usr1/program/ curl -L https://td-toolbelt.herokuapp.com/sh/install-redhat-td-agent2.sh | sh # /etc/init.d/td-agent start /etc/init.d/td-agent status /etc/init.d/td-agent restart /etc/init.d/td-agent stop # cat /etc/td-agent/td-agent.conf # curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test tail -f /var/log/td-agent/td-agent.log Collector [ec-ldb-m2] Service DB [ec-ldb-s2]
  • 12. 12 Index 1. Intro 2. Install 3. Test MySQL slowquery logging MySQL process list logging Game Log Data Collect Log Server 蟲豢 4. QnA
  • 13. 13 Step.1 讌 覯襦 Fluentd plugin れ https://github.com/yuku-t/fluent-plugin-mysqlslowquery https://github.com/tagomoris/fluent-plugin-mysql https://github.com/toyama0919/fluent-plugin-mysql-bulk # yum -y install ruby-rdoc ruby-devel rubygems find / -name fluent-gem /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysqlslowquery /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysql-bulk Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.1 MySQL slowquery logging
  • 14. 14 Test.1 MySQL slowquery logging Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.2 讌蠍(Collector) 覯襦 Log 企 $ mysql -u root -p use test; drop table if exists test.t_mysql_slow; create table test.t_mysql_slow ( log_date datetime default current_timestamp , user varchar(100) , host varchar(100) , host_ip varchar(20) , query_time decimal(20,10) , lock_time decimal(20,10) , rows_sent bigint , rows_examined bigint , sql_text varchar(10000) );
  • 15. 15 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.3 讌(DB) 覯襦 td-agent.conf れ $ sudo vi /etc/td-agent/td-agent.conf <source> type mysql_slow_query path /data/mysql/ADMIN/slowquery.log tag ec-ldb-m2.mysql_slow </source> <match ec-ldb-m2.mysql_slow> type copy <store> type stdout </store> <store> type mysql_bulk host ec-ldb-m2 port 19336 database test username root password testpasswd12#$ column_names user,host,host_ip,query_time,lock_time,rows_sent,rows_examined,sql_text key_names user,host,host_ip,query_time,lock_time,rows_sent,rows_examined,sql_text table t_mysql_slow flush_interval 5s </store> </match> Test.1 MySQL slowquery logging
  • 16. 16 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.4 td-agent 覦 覿貎朱Μ $ sudo /etc/init.d/td-agent stop sudo /etc/init.d/td-agent start tail -f /var/log/td-agent/td-agent.log Test.1 MySQL slowquery logging $ mysql -u root -p select sleep(1); select sleep(1);
  • 17. 17 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.5 讌蠍(Collector) 覯 襦蠏 $ mysql -u root p select sleep(1); select sleep(1); Test.1 MySQL slowquery logging $ mysql -u root -p select * from t_mysql_slow;
  • 18. 18 Index 1. Intro 2. Install 3. Test MySQL slowquery logging MySQL process list logging Game Log Data Collect Log Server 蟲豢 4. QnA
  • 19. 19 Step.1 讌 覯襦 Fluentd plugin れ https://github.com/y-ken/fluent-plugin-mysql-query https://github.com/shunwen/fluent-plugin-rename-key # yum -y install ruby-rdoc ruby-devel rubygems find / -name fluent-gem /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysql-query /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-rename-key Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.2 MySQL process list logging
  • 20. 20 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.2 MySQL process list logging Step.2 讌蠍(Collector) 覯襦 Log 企 $ mysql -u root -p use test; drop table if exists test.t_mysql_process; create table test.t_mysql_process ( log_date datetime default current_timestamp , hostname varchar(100) , id bigint , user varchar(100) , host varchar(100) , db varchar(64) , command varchar(50) , duration_time bigint , state varchar(4000) , info varchar(10000) );
  • 21. 21 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.2 MySQL process list logging Step.3 讌(DB) 覯襦 td-agent.conf れ $ sudo vi /etc/td-agent/td-agent.conf <source> type mysql_query host ec-ldb-s2 port 19336 database test username root password 433dlxjsjf12!@! interval 1m tag ec-ldb-s2.processlist query show full processlist; record_hostname yes nest_result no nest_key data #row_count yes #row_count_key row_count </source> <match ec-ldb-s2.processlist> type rename_key remove_tag_prefix ec-ldb-s2. append_tag ec-ldb-s2 rename_rule1 Time duration_time </match> <match processlist.ec-ldb-s2> type copy <store> type stdout </store> <store> type mysql_bulk host ec-ldb-m2 port 19336 database test username root password testpasswd12#$ column_names hostname,Id,User,Host,db,Command,State,Info,duration_time key_names hostname,Id,User,Host,db,Command,State,Info,duration_time table t_mysql_process flush_interval 5s </store> </match>
  • 22. 22 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.2 MySQL process list logging Step.4 td-agent $ sudo /etc/init.d/td-agent stop sudo /etc/init.d/td-agent start tail -f /var/log/td-agent/td-agent.log
  • 23. 23 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.2 MySQL process list logging Step.5 讌蠍(Collector) 覯 襦蠏 $ mysql -u root p use test; select * from t_mysql_process;
  • 24. 24 Index 1. Intro 2. Install 3. Test MySQL slowquery logging MySQL process list logging Game Log Data Collect Log Server 蟲豢 4. QnA
  • 25. 25 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.1 讌蠍(Collector) 覯襦 Log 企 $ mysql -u root -p use test; drop table if exists test.log_game_play; create table test.log_game_play ( log_date datetime default current_timestamp , useridx bigint , play_time bigint , char_type varchar(1) , result varchar(1) ); alter table log_game_play add primary key(log_date,useridx); Test.3 Game Log Collect
  • 26. 26 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.2 讌 覯襦 Log 企 覦 一危 $ mysql -u root -p use test; drop table if exists test.log_game_play; create table test.log_game_play ( log_date datetime default current_timestamp , useridx bigint , play_time bigint , char_type varchar(1) , result varchar(1) ); alter table log_game_play add primary key(log_date,useridx); Test.3 Game Log Collect set @i=0; insert ignore into test.log_game_play select date_sub(now(), interval @i:=@i+1 minute) as log_date , @i , rand()*10000 , mod(@i,10) , mod(@i,3) from mysql.proc limit 100; select date_format(log_date, '%Y%m%d%h') as dt, count(*) from test.log_game_play group by date_format(log_date, '%Y%m%d%h'); select * from test.log_game_play where log_date between date_sub(now(), interval 10 minute) and now();
  • 27. 27 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.3 讌(DB) 覯襦 td-agent.conf れ $ sudo vi /etc/td-agent/td-agent.conf <source> type mysql_query host ec-ldb-s2 port 19336 database test username root password 433dlxjsjf12!@! interval 10s tag ec-ldb-s2.log_game_play query select * from test.log_game_play where log_date between date_sub(now(), interval 10 minute) and now(); record_hostname yes nest_result no nest_key data #row_count yes #row_count_key row_count </source> <match ec-ldb-s2.log_game_play> type copy <store> type stdout </store> <store> type mysql_bulk host ec-ldb-m2 port 19336 database test username root password 433dlxjsjf12!@! column_names log_date,useridx,play_time,char_type,result key_names log_date,useridx,play_time,char_type,result table log_game_play on_duplicate_key_update true on_duplicate_update_keys log_date,useridx flush_interval 15s </store> </match> Test.3 Game Log Collect
  • 28. 28 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.4 td-agent $ sudo /etc/init.d/td-agent stop sudo /etc/init.d/td-agent start tail -f /var/log/td-agent/td-agent.log Test.3 Game Log Collect
  • 29. 29 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.5 讌蠍(Collector) 覯 襦蠏 $ mysql -u root p use test; select * from test.log_game_play; Test.3 Game Log Collect
  • 30. 30 Index 1. Intro 2. Install 3. Test MySQL slowquery logging MySQL process list logging Game Log Data Collect Log Server 蟲豢 4. QnA
  • 31. 31 Step.1 讌 覯襦 Fluentd plugin れ https://github.com/tagomoris/fluent-plugin-mysql # yum -y install ruby-rdoc ruby-devel rubygems find / -name fluent-gem /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-mysql Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Test.4 Log Server 蟲豢 Client Client Client Server Server HAProxy(L4)
  • 32. 32 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.2 讌蠍(Collector) 覯襦 Log 企 $ mysql -u root -p use test; drop table if exists test.t_log_connect; create table test.t_log_connect ( log_date datetime default current_timestamp , jsondata text ); drop table if exists test.t_log_money; create table test.t_log_money ( log_date datetime default current_timestamp , jsondata text ); Test.4 Log Server 蟲豢
  • 33. 33 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.3 讌(DB) 覯襦 td-agent.conf れ $ sudo vi /etc/td-agent/td-agent.conf <source> type http port 8888 body_size_limit 1mb keepalive_timeout 10s </source> <match ec-ldb-s2.t_log_connect> type copy <store> type stdout </store> <store> type mysql host ec-ldb-m2 port 19336 database test username root password testpasswd12#$ table t_log_connect columns jsondata format json flush_interval 5s </store> </match> <match ec-ldb-s2.t_log_money> type copy <store> type stdout </store> <store> type mysql host ec-ldb-m2 port 19336 database test username root password testpasswd12#$ table t_log_money columns jsondata format json flush_interval 5s </store> </match> Test.4 Log Server 蟲豢
  • 34. 34 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.4 td-agent $ sudo /etc/init.d/td-agent stop sudo /etc/init.d/td-agent start -- 襦蠏 覦 curl -X POST -d 'json={"ver":"1.0","action":"login","user":1}' http://localhost:8888/ec-ldb-s2.t_log_connect curl -X POST -d 'json={"ver":"1.0","action":"login","user":1}' http://localhost:8888/ec-ldb-s2.t_log_money tail -f /var/log/td-agent/td-agent.log Test.4 Log Server 蟲豢
  • 35. 35 Collector [ec-ldb-m2] Service DB [ec-ldb-s2] Step.5 讌蠍(Collector) 覯 襦蠏 $ mysql -u root p use test; select count(*) from test.t_log_money; select count(*) from test.t_log_connect; Test.4 Log Server 蟲豢
  • 37. 37 Test.0 覦 BackupDB Service.1 Service.2 Service.3 1. federated engine or Export/Import 伎 襷れ 3螳 伎 Log Data 襯 覦煙覦 1. 轟蠍郁 伎 螻手碓 一危磯ゼ 10覿襦 覦煙 覦朱 覿 覦一 蟇 2. 譯殊 讌 一危一 伎 ETL 豌危 讌 蟾? Fluentd Agent Pool
  • 38. 38 Reference RubyConf 2014 - Build the Unified Logging Layer with Fluentd and Ruby by Kiyoto Tamura https://www.youtube.com/watch?v=sIVGsQgMHIo
  • 39. 39