2. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
2
3. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
3
4. Intro 4
• 1,500 persons
• 20,000,000,000 yen
slow_query
Collect DB
WEB VIEWER
1st Devleopement
2nd Devleopement
3nd Devleopement
MySS architecture
5. Intro 5
• 1,500 persons
• 20,000,000,000 yen
3nd Development ???
(real time slow query)
10. Intro 10
구분
강조점 유연성 / 상호운용성 단순함 / 안정성
구현언어 J 루비(Jruby) C루비(Cruby)
입력방법 많음 적음
플러그인 많음 매우 많음
플러그인 설치 쉬움 (jar 배포) 쉬움 (gem 설치)
신뢰성 메시지 loss 가능성 있음 메시지 loss 없음
11. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
11
17. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
17
18. Install 18
1. Install
> curl -L https://td-toolbelt.herokuapp.com/sh/install-redhat-td-agent2.sh | sh
2. Start demon
> service td-agent start
Starting td-agent: [ OK ]
> service td-agent status
td-agent (pid 2567) is running
> service td-agent restart
> service td-agent stop
> td-agent --version
td-agent 0.12.12
3. Transfer Sample Log
> curl -X POST -d 'json={"json":"message"}' http://localhost:8888/debug.test.test
> tail -n 1 /var/log/td-agent/td-agent.log
2015-09-10 00:26:31 +0900 debug.test.test: {"json":"message"}
19. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
19
20. Test 20
MySQL : slow query
<source>
type mysql_slow_query
path /mysql/logs/slow_query.log
pos_file /mysql/logs/slow_query.pos
tag raw.collect.mysql_slow
</source>
<match raw.collect.mysql_slow>
type parser
remove_prefix raw
format /^SET timestamp=(?<time_stamp>[^;]*); (?<sql>[^;]*);$/
time_format %d/%b/%Y:%H:%M:%S %z
key_name sql
reserve_data yes
</match>
<match collect.mysql_slow>
type hostname
key_name hostname
add_prefix filtered
</match>
<match filtered.collect.mysql_slow>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host 192.168.95.57
port 3306
database DBPart
username root
password rex
column_names
hostname,user,host,db,query_time,lock_time,rows_sent,rows_examined,ti
me_stamp,sql_text
key_names
hostname,user,host,db,query_time,lock_time,rows_sent,rows_examined,ti
me_stamp,sql
table t_mysql_slow
flush_interval 5s
</store>
</match>
24. Test 24
MySQL : slow query
> vi /etc/td-agent/td-agent.conf
=========================================================
...
<source>
type mysql_slow_query
path /mysql/logs/slow_query.log
tag collect.mysql_slow
</source>
<match collect.mysql_slow>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host 192.168.95.100
port 3306
database DBPart
username root
password rex
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
table t_mysql_slow
flush_interval 5s
</store>
</match>
=========================================================
25. Test 25
MySQL : slow query
3. td-agent restart
service td-agent stop
Shutting down td-agent: [ OK ]
service td-agent start
Starting td-agent: [ OK ]
4. press slow query
mysql -u root -p
use mysql;
select sleep(1);
select sleep(1);
[root@localhost ~]# tail -f /var/log/td-agent/td-agent.log
2015-09-10 12:06:31 +0900 collect.mysql_slow:
{"user":"root[root]","host":"localhost","host_ip":"","query_time":1.000855,"lock_time":0.0,"rows_sent":1,"rows_examine
d":0,"sql":"SET timestamp=1441854391; select sleep(1);","db":"mysql"}
2015-09-10 12:06:33 +0900 collect.mysql_slow:
{"user":"root[root]","host":"localhost","host_ip":"","query_time":1.000862,"lock_time":0.0,"rows_sent":1,"rows_examine
d":0,"sql":"SET timestamp=1441854393; select sleep(1);","db":"mysql"}
2015-09-10 12:24:16 +0900 [info]: bulk insert values size => 2
* SERVER
mysql> select * from t_mysql_slow;
+---------------------+------------+-----------+---------+--------------+--------------+-----------+---------------+--------------------------------------------+----------+
| log_date | user | host | host_ip | query_time | lock_time | rows_sent | rows_examined | sql_text | hostname |
+---------------------+------------+-----------+---------+--------------+--------------+-----------+---------------+--------------------------------------------+----------+
| 2015-09-10 07:03:45 | root[root] | localhost | | 1.0008600000 | 0.0000000000 | 1 | 0 | SET timestamp=1441820542; select sleep(1); | NULL |
| 2015-09-10 07:04:15 | root[root] | localhost | | 1.0010030000 | 0.0000000000 | 1 | 0 | SET timestamp=1441820574; select sleep(1); | NULL |
+---------------------+------------+-----------+---------+--------------+--------------+-----------+---------------+--------------------------------------------+----------+
8 rows in set (0.00 sec)
26. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
26
27. Test 27
MySQL : show processlist
<source>
type mysql_query
host 192.168.95.222
port 3306
database DBPart
username root
password rex
interval 10s
tag client.processlist
query show full processlist;
record_hostname yes
nest_result no
nest_key data
</source>
<match client.processlist>
type rename_key
remove_tag_prefix client.
append_tag client
rename_rule1 Time duration_time
</match>
<match processlist.client>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host 192.168.95.57
port 3306
database DBPart
username root
password rex
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>
28. Test 28
* Tail Log
* MySQL Data
MySQL : show processlist
29. Test 29
MySQL : show processlist
# Server
1. Create Log table in Collector Server
mysql -u root -p
use DBPart;
drop table if exists DBPart.t_mysql_process;
create table DBPart.t_mysql_process (
hostname varchar(100)
, log_date datetime default current_timestamp
, id bigint
, user varchar(100)
, host varchar(100)
, db varchar(64)
, command varchar(50)
, duration_time bigint
, state varchar(4000)
, info varchar(10000)
);
31. Test 31
MySQL : show processlist
> vi /etc/td-agent/td-agent.conf
=========================================
...
### mysql show processlist
<source>
type mysql_query
host 192.168.95.222
port 3306
database DBPart
username root
password rex
interval 10s
tag client.processlist
query show full processlist;
record_hostname yes
nest_result no
nest_key data
#row_count yes
#row_count_key row_count
</source>
<match client.processlist>
type rename_key
remove_tag_prefix client.
append_tag client
rename_rule1 Time duration_time
</match>
<match processlist.client>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host 192.168.95.57
port 3306
database DBPart
username root
password rex
column_names
hostname,Id,User,Host,db,Command,State,Info,duratio
n_time
key_names
hostname,Id,User,Host,db,Command,State,Info,duratio
n_time
table t_mysql_process
flush_interval 5s
</store>
</match>
=========================================
32. Test 32
MySQL : show processlist
3. td-agent restart
service td-agent stop
Shutting down td-agent: [ OK ]
service td-agent start
Starting td-agent: [ OK ]
4. show processlist;
* client
mysql -u root -p
root@localhost:(none) 14:43:47>show processlist;
+----+------+----------------------+--------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------+----------------------+--------+---------+------+-------+------------------+
| 3 | root | localhost | NULL | Sleep | 381 | | NULL |
| 7 | root | localhost | NULL | Query | 0 | init | show processlist |
| 9 | root | 192.168.95.222:59359 | DBPart | Sleep | 43 | | NULL |
| 10 | root | localhost | NULL | Sleep | 3 | | NULL |
+----+------+----------------------+--------+---------+------+-------+------------------+
4 rows in set (0.00 sec)
[root@localhost ~]# tail -f /var/log/td-agent/td-agent.log
…
2015-09-10 14:47:29 +0900 processlist.collect: {"hostname":"localhost.localdomain","Id":"3","User":"root","Host":"localhost","db":null,"Command":"Sleep","duration_time":"578","State":"","Info":null}
2015-09-10 14:47:29 +0900 processlist.collect: {"hostname":"localhost.localdomain","Id":"7","User":"root","Host":"localhost","db":null,"Command":"Sleep","duration_time":"60","State":"","Info":null}
2015-09-10 14:47:29 +0900 processlist.collect:
{"hostname":"localhost.localdomain","Id":"9","User":"root","Host":"192.168.95.222:59359","db":"DBPart","Command":"Query","duration_time":"0","State":"init","Info":"show full processlist"}
2015-09-10 14:47:30 +0900 [info]: bulk insert values size => 3
--> Send every 1 minutes
36. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Error / Load test
V. To do
VI. Reference
INDEX
Agenda
36
46. Test 46
Load Test
### Conclusion
* Case1 : no fluentd agent press
- cpu : idle 94~100% (used +5%)
- mem : used 741M (used +4M)
- I/O : read 32K~64K, write 12K~32K
* Case2 : Fluentd agent press
- cpu : idle 95~100% (used +4%)
- mem : used 809M (used +4M)
- I/O : read 32K~64K, write 16K~36K
>>> the load is not at all due to the agent. (only 60M)
* 800,000 p/s logging
47. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
47
48. To do 48
• MySQL : slow query log
• MySQL : process list
• MySQL : show global status
• Apache : web log
• Linux : Syslog
• Linux : df command
• Linux : dstat command . . . . .
49. To do 49
• 1,500 persons
• 20,000,000,000 yen
slow_query
Collect DB
WEB VIEWER
1st Devleopement
2nd Devleopement
3nd Devleopement
3nd Development ???
52. 52
MySQL : ETL
<source>
type mysql_query
host rex
port 3306
database test
username root
password rex
interval 10s
tag rex.log_game_play
query select * from test.log_game_play where log_dat
e between date_sub(now(), interval 10 minute) and now
();
record_hostname yes
nest_result no
nest_key data
</source>
<match rex.log_game_play>
type copy
<store>
type stdout
</store>
<store>
type mysql_bulk
host rex
port 3306
database test
username root
password rex
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>
To do
54. I. Intro
II. Architecture
III. Install
IV. Test
- MySQL slowquery logging
- MySQL processlist logging
- Load test
V. To do
VI. Reference
INDEX
Agenda
54