我使用AWS ElasticBeanstalk和Tomcat作为Web服务器。我想调试并记录Java虚拟机性能,崩溃报告并将它们写入CloudWatch Logs。
目前,AWS ElasticBeanstalk收集由Web服务器,应用程序服务器,Elastic Beanstalk平台脚本创建的日志。您可以将CloudWatch日志用作集中式日志系统。
我如何在开始时提到的CloudWatch中收集自定义JVM日志?
感谢。
林
答案 0 :(得分:0)
我已经联系了AWS支持团队,他们的答案是:
这可以使用.ebextensions配置文件安装awslogs软件包并定义日志文件,log_group_name和log_stream名称以在CloudWatch上流式传输来完成,
请在下面找到用于在CloudWatch for Tomcat8环境中启用Catalina日志的示例 ---。ebextensions / cwatch.config ---
packages:
yum:
awslogs: []
files:
"/etc/awslogs/awscli.conf" :
mode: "000600"
owner: root
group: root
content: |
[plugins]
cwlogs = cwlogs
[default]
region = `{"Ref":"AWS::Region"}`
"/etc/awslogs/awslogs.conf" :
mode: "000600"
owner: root
group: root
content: |
[general]
state_file = /var/lib/awslogs/agent-state
[/var/log/tomcat8]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "catalina"]]}`
log_stream_name = {instance_id}_messages
file = /var/log/tomcat8/catalina.out
datetime_format = %b %d %H:%M:%S
initial_position = start_of_file
buffer_duration = 5000
[/var/log/messages]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "syslog"]]}`
log_stream_name = {instance_id}_messages
file = /var/log/messages
datetime_format = %b %d %H:%M:%S
initial_position = start_of_file
buffer_duration = 5000
[/var/log/eb-activity.log]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "eb"]]}`
log_stream_name = {instance_id}_eb-activity.log
file = /var/log/eb-activity.log
datetime_format = [%Y-%m-%dT%H:%M:%S.%3NZ]
initial_position = start_of_file
buffer_duration = 5000
[/var/log/eb-cfn-init.log]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "eb"]]}`
log_stream_name = {instance_id}_eb-cfn-init.log
file = /var/log/eb-cfn-init.log
datetime_format = [%Y-%m-%dT%H:%M:%S.%3NZ]
initial_position = start_of_file
buffer_duration = 5000
[/var/log/eb-commandprocessor.log]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "eb"]]}`
log_stream_name = {instance_id}_eb-commandprocessor.log
file = /var/log/eb-commandprocessor.log
datetime_format = [%Y-%m-%dT%H:%M:%S.%3NZ]
initial_position = start_of_file
buffer_duration = 5000
[/var/log/eb-publish-logs.log]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "eb"]]}`
log_stream_name = {instance_id}_eb-publish-logs.log
file = /var/log/eb-publish-logs.log
datetime_format = %Y-%m-%d %H:%M:%S,%3N
initial_position = start_of_file
buffer_duration = 5000
[/var/log/eb-tools.log]
log_group_name = `{"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "eb"]]}`
log_stream_name = {instance_id}_eb-tools.log
file = /var/log/eb-tools.log
datetime_format = %Y-%m-%d %H:%M:%S,%3N
initial_position = start_of_file
buffer_duration = 5000
commands:
"01":
command: chkconfig awslogs on
"02":
command: service awslogs restart
---end---
and here is a simpler version to Add log to default CloudWatch logs streaming config
Warning: does not set retention policy, won't obey retention policy (e.g "delete when env is deleted)
---.ebextensions/log.config---
files:
/etc/awslogs/config/mylog.conf:
owner: root
group: root
mode: "000644"
content:
Fn::Sub: |
[/var/log/mylog.log]
log_group_name=/aws/elasticbeanstalk/${AWSEBEnvironmentName}/var/log/mylog.log
log_stream_name={instance_id}
file=/var/log/mylog.log
commands:
restart_awslogs:
command: service awslogs restart || service awslogs start
---end---
注意:请勿使用生产中提供的样品。该示例的目的是说明功能。” 我没有检查它,但是如果有人将测试此解决方案,请发表评论并将其标记为有效。如果没有,我将删除答案。