Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to run Filebeat on Docker #73

Open
zmoog opened this issue Jan 19, 2024 · 5 comments
Open

Figure out how to run Filebeat on Docker #73

zmoog opened this issue Jan 19, 2024 · 5 comments
Assignees
Labels

Comments

@zmoog
Copy link
Owner

zmoog commented Jan 19, 2024

I want to run Filebeat 8.11.3 with a custom configuration on Docker for testing purpose.

Requisites:

  • Access configuration files filebeat.yml using volume.
  • Write events to a local folder using the Filebeat file output.
@zmoog zmoog added the research label Jan 19, 2024
@zmoog zmoog self-assigned this Jan 19, 2024
@zmoog zmoog added this to Notes Jan 19, 2024
@zmoog
Copy link
Owner Author

zmoog commented Jan 19, 2024

@zmoog zmoog moved this to In Progress in Notes Jan 19, 2024
@zmoog
Copy link
Owner Author

zmoog commented Jan 19, 2024

Pull the image

docker pull docker.elastic.co/beats/filebeat:8.11.3

@zmoog
Copy link
Owner Author

zmoog commented Jan 19, 2024

Configure Filebeat

 cat filebeat.yml
# ================================== General ====================================
fields_under_root: true
fields:
  service:
    environment: ${ENVIRONMENT}
    app: ${APP_NAME}
    prefix: ${SERVICE_PREFIX}
    name: ${SERVICE_PREFIX}-${ENVIRONMENT}-${APP_NAME}

# ============================== Filebeat inputs ===============================

filebeat.inputs:

  # Each - is an input. Most options can be set at the input level, so
  # you can use different inputs for various configurations.
  # Below are the input-specific configurations.

  # apigw-access
  - type: aws-s3
    enabled: true
    queue_url: "${SQS_QUEUE_URL}"
    access_key_id: "${AWS_ACCESS_KEY_ID}"
    secret_access_key: "${AWS_SECRET_ACCESS_KEY}"
    api_timeout: 30s
    visibility_timeout: 10s
    sqs.max_receive_count: -1
    sqs.wait_time: 20s
    fields:
      service:
        log_type: "apigw-access"
    fields_under_root: true

output.file:
  path: "/tmp/filebeat/"
  filename: filebeat
  rotate_every_kb: 10000
  number_of_files: 7

# ================================== Logging ===================================

logging:
  level: ${LOG_LEVEL:debug}
  metrics:
    enabled: false
  to_files: true
  files:
    path: /tmp/filebeat/log/filebeat
    interval: 86400
    rotateeverybytes: 31457280
    keepfiles: 7
    permissions: 0644
    rotateonstartup: false

processors:
  - add_host_metadata:
      when.not.contains.tags: forwarded
      #  - add_cloud_metadata: ~
      #  - add_docker_metadata: ~

@zmoog
Copy link
Owner Author

zmoog commented Jan 19, 2024

Run volume-mounted configuration

Run Filebeat using filebeat.yml file using ./tmp/filebeat/ as output:

docker run \
  --rm \
  --name=filebeat \
  --user=root \
  --volume="$(pwd)/filebeat.yml:/usr/share/filebeat/filebeat.yml:ro" \
  --volume="$(pwd)/tmp:/tmp" \
  --volume="/var/lib/docker/containers:/var/lib/docker/containers:ro" \
  --volume="/var/run/docker.sock:/var/run/docker.sock:ro" \
  --volume="registry:/usr/share/filebeat/data:rw" \
  docker.elastic.co/beats/filebeat:8.11.3 filebeat -e --strict.perms=false \
  -E AWS_ACCESS_KEY_ID="<REDACTED>" \
  -E AWS_SECRET_ACCESS_KEY="<REDACTED>" \
  -E SQS_QUEUE_URL="<REDACTED>" \
  -E ENVIRONMENT=dev \
  -E APP_NAME=myapp \
  -E SERVICE_PREFIX=prefix 

@zmoog
Copy link
Owner Author

zmoog commented Jan 19, 2024

Testing

I use a sample file to the SQS_QUEUE_URL:

aws s3 cp test_file.gz s3://S3_BUCKET/6.gz

And here's what I see in the ./tmp/ folder:

$ tree tmp/
tmp/
└── filebeat
    └── filebeat-20240119.ndjson

1 directory, 1 file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Progress
Development

No branches or pull requests

1 participant