# 将json格式gamelog日志中table中含有table:login的json日志写入player表中,
# 将table表中table:online的日志写入renshu表中
测试日志gamelog:
{"line": "11", "table": "online"}
{"name": "xc", "uid": "2574433315", "newBee": true, "table": "login"}
{"name": "xc", "uid": "2574433315", "newBee": false}
input {
file {
path => "/db/log/gamelog"
start_position => "beginning"
stat_interval => "2"
}
}
filter {
grok {
#GREEDYDATA表达式的意思能匹配任意字符串
# WORD 匹配字符
match => {"message" => "\[%{WORD:table}\],%{GREEDYDATA:message}"}
overwrite => [ "message" ]
}
json {
source => "message"
skip_on_invalid_json => true
}
mutate {
remove_field => ["@version", "@timestamp", "path", "status","tags"]
}
}
output {
stdout {codec => json_lines}
if [table] == "login" {
analyticdb {
driver_jar_path => "/usr/local/logstash/vendor/jar/jdbc/mysql-connector-java-5.1.49.jar"
driver_class => "com.mysql.jdbc.Driver"
connection_string => "jdbc:mysql://192.168.10.14:3306/log_db?user=game&password=wg1q2w3e&useUnicode=true&characterEncoding=utf8&useSSL=false"
statement => ["INSERT INTO player(accountid,nickname) VALUES(?,?)","uid","name"]
}
}
if [table] == "online" {
analyticdb {
driver_jar_path => "/usr/local/logstash/vendor/jar/jdbc/mysql-connector-java-5.1.49.jar"
driver_class => "com.mysql.jdbc.Driver"
connection_string => "jdbc:mysql://192.168.10.14:3306/log_db?user=game&password=wg1q2w3e&useUnicode=true&characterEncoding=utf8&useSSL=false"
statement => ["INSERT INTO renshu(pcu) VALUES(?)","line"]
}
}
}