Skip to content

Instantly share code, notes, and snippets.

@mrk21
Created June 13, 2019 06:11
Show Gist options
  • Save mrk21/fa5e2e527efb3b59ac50bc84219ce583 to your computer and use it in GitHub Desktop.
Save mrk21/fa5e2e527efb3b59ac50bc84219ce583 to your computer and use it in GitHub Desktop.
Fluent config sample that outputs logs to stdout, S3 and Cloudwatch Logs
---
version: '3.5'
services:
fluentd:
build:
context: .
dockerfile: docker/fluentd/Dockerfile
target: base
ports:
- ${DOCKER_HOST_FLUENTD_PORT:-24224}:24224
- ${DOCKER_HOST_FLUENTD_PORT:-24224}:24224/udp
volumes:
- ./docker/fluentd/fluent.conf:/fluentd/etc/fluent.conf:ro
environment:
AWS_REGION: ${FLUENTD_AWS_REGION:-}
AWS_ACCESS_KEY_ID: ${FLUENTD_AWS_ACCESS_KEY_ID:-}
AWS_SECRET_ACCESS_KEY: ${FLUENTD_AWS_SECRET_ACCESS_KEY:-}
# for development
FROM fluent/fluentd as base
RUN gem install fluent-plugin-s3 -v 1.1.10 --no-document
RUN gem install fluent-plugin-cloudwatch-logs -v 0.7.3 --no-document
# for production
FROM base AS bundle
COPY docker/fluentd/fluent.conf /fluentd/etc/fluent.conf
<source>
@type forward
@label @applog
port 24224
bind 0.0.0.0
</source>
<label @applog>
<match lograge.*>
@type copy
<store>
@type stdout
</store>
<store>
@type s3
aws_key_id "#{ENV['AWS_ACCESS_KEY_ID']}"
aws_sec_key "#{ENV['AWS_SECRET_ACCESS_KEY']}"
s3_region "#{ENV['AWS_REGION']}"
s3_bucket fluentd-test
path app/lograge/%Y-%m-%d/
s3_object_key_format %{path}%{index}.%{file_extension}
time_slice_format %Y/%m/%d
<format>
@type json
</format>
<buffer time>
@type file
path /tmp
timekey 1m
timekey_wait 0
</buffer>
</store>
<store>
@type cloudwatch_logs
log_group_name fluentd-test
log_stream_name fluentd-test
auto_create_stream true
</store>
</match>
</label>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment