정규표현식을 통해 데이터를 JSON으로 변환한다. https://rubular.com/ 에서 정규식을 테스트할 수 있다.
sudo yum install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user
sudo chmod 666 /var/run/docker.sock
docker pull fluent/fluent-bit:latest
cat <<EOF > Dockerfile
FROM fluent/fluent-bit:latest
COPY ./fluent-bit.conf /fluent-bit/etc/fluent-bit.conf
COPY ./my-parser.conf /fluent-bit/etc/my-parser.conf
COPY ./script.lua /fluent-bit/etc/script.lua
EOF
cat <<EOF > fluent-bit.conf
[SERVICE]
Flush 1
Daemon off
Parsers_file my-parser.conf
[INPUT]
Name tail
Path /var/log/logf/gin.log # 수정
Parser my-parser
Tag app
[FILTER]
Name lua
Match *
script script.lua
call modify
[OUTPUT]
Name kinesis_streams
match *
region ap-northeast-2
stream skills-stream # 수정
[OUTPUT]
Name stdout
Match *
EOF
cat <<EOF > my-parser.conf
[PARSER]
Name my-parser
Format regex
Regex # 추가
EOF
cat <<EOF > script.lua
function modify(tag, timestamp, record)
new_record = record
return 1, timestamp, new_record
end
EOF
docker build -t my-fluent-bit:latest .
docker run -v /home/ec2-user/:/var/log/logf/ my-fluent-bit:latest # 수정