简体   繁体   English

流文件日志到CloudWatch

[英]Stream file log to cloudwatch

I have an EC2-instance running docker using docker-compose. 我有一个使用docker-compose运行docker的EC2实例。 I would like all logs written to a file by one of the applications to send that data async to CloudWatch. 我希望所有应用程序之一将所有日志写入文件,以将该数据异步发送到CloudWatch。 It would be ideal to have a separate container that is sharing the logs directory with the application container and runs something like tail -f and sends the output to CloudWatch. 最好有一个单独的容器,该容器与应用程序容器共享日志目录,并运行tail -f类的东西并将输出发送到CloudWatch。

I am no expert, but I imagine that Filebeat does something similar, but Don't know if I can configure it to send to CloudWatch. 我不是专家,但我想Filebeat可以执行类似的操作,但是不知道是否可以将其配置为发送到CloudWatch。

So I ended up using this docker image 所以我最终使用了这个docker镜像

This is my service in my docker-compose.yml 这是我在docker-compose.yml中的服务

  cloudwatch:
    image: iconara/awslogs:latest
    command: "--region eu-central-1 --config-file /etc/awslogs/app.conf"
    volumes:
      - ./environment/cloudwatch/conf/awscli.conf:/etc/awslogs/app.conf
      - ./environment/cloudwatch/state:/var/lib/awslogs/
      - ./logs:/app-logs/general/
      - ./project/storage/logs:/app-logs/laravel/
      - ~/.aws:/root/.aws

I am mounting the credentials so I can use this for development on Mac OSX which is probably not needed on an EC2 instance, depending on your setup. 我正在安装凭据,因此可以将其用于在Mac OSX上进行开发,这在EC2实例上可能不需要,具体取决于您的设置。 I also mounted the state file so that the same logs wont be pushed twice if the container is restarted. 我还安装了状态文件,以便在重新启动容器时不会将相同的日志推送两次。

This is my ./environment/cloudwatch/conf/awscli.conf 这是我的./environment/cloudwatch/conf/awscli.conf

[general]
state_file = /var/lib/awslogs/agent-state
use_gzip_http_content_encoding = true

[/app-logs/logs/laravel.log]
datetime_format = %Y-%m-%d %H:%M:%S
file = /app-logs/laravel/laravel.log
buffer_duration = 5000
#log_stream_name = {instance_id}
log_stream_name = development
initial_position = start_of_file
log_group_name = /app-logs/laravel/laravel.log
multi_line_start_pattern = {datetime_format}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM