亚马逊提供这些现成的文件,用于将Tomcat / Apache / nginx日志发送到Cloudwatch日志,这些日志非常有效。
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html
然而,出于我的目的,他们只发送nginx日志,这实际上是不够的,不幸的是他们也提供了关于文件格式的零文档。我想要实现的是将node.js日志从我的Docker应用程序发送到Cloudwatch(因为自动缩放会使实例来去)。
因此,像/var/log/eb-docker/containers/eb-current-app/add839a3b599-stdouterr.log
这样的文件会出现在Cloudwatch中。
所以,到目前为止我尝试过的是从上面的链接调整webrequests配置:
##############################################################################
## Sends docker logs to CloudWatch Logs
##############################################################################
Mappings:
CWLogs:
ApplicationLogGroup:
LogFile: "/var/log/eb-docker/containers/eb-current-app/*-stdouterr.log"
TimestampFormat: "%Y-%m-%d %H:%M:%S"
Outputs:
ApplicationLogGroup:
Description: "The name of the Cloudwatch Logs Log Group created for this environments web server access logs. You can specify this by setting the value for the environment variable: WebRequestCWLogGroup. Please note: if you update this value, then you will need to go and clear out the old cloudwatch logs group and delete it through Cloudwatch Logs."
Value: { "Ref" : "AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0ApplicationLogGroup"}
Resources :
AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0ApplicationLogGroup: ## Must have prefix: AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0
Type: "AWS::Logs::LogGroup"
DependsOn: AWSEBBeanstalkMetadata
DeletionPolicy: Retain ## this is required
Properties:
LogGroupName:
"Fn::GetOptionSetting":
Namespace: "aws:elasticbeanstalk:application:environment"
OptionName: ApplicationLogGroup
DefaultValue: {"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "stdouterr"]]}
RetentionInDays: 14
## Register the files/log groups for monitoring
AWSEBAutoScalingGroup:
Metadata:
"AWS::CloudFormation::Init":
CWLogsAgentConfigSetup:
files:
## any .conf file put into /tmp/cwlogs/conf.d will be added to the cwlogs config (see cwl-agent.config)
"/tmp/cwlogs/conf.d/stdouterr.conf":
content : |
[stdouterr]
file = `{"Fn::FindInMap":["CWLogs", "ApplicationLogGroup", "LogFile"]}`
log_group_name = `{ "Ref" : "AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0ApplicationLogGroup" }`
log_stream_name = {instance_id}
datetime_format = `{"Fn::FindInMap":["CWLogs", "ApplicationLogGroup", "TimestampFormat"]}`
mode : "000400"
owner : root
group : root
不幸的是,这似乎不起作用。 :/
此外,如果有fe,是否有人知道日志是否会出现。时间戳格式错了?特别重要,因为默认情况下,异常并没有真正的时间戳,所以实际的错误就会消失。
我的应用程序日志行目前如下所示:
2016-07-05 09:11:31 ::1 - GET / 200 (5.107 ms)
答案 0 :(得分:0)
您可以使用此链接在您的beanstalk实例上设置cloudwatch代理(如果您还没有) - http://serebrov.github.io/html/2015-05-20-cloudwatch-setup.html。
下一步 - 尝试发送/var/lib/docker/containers//.json中的文件来收集您的docker日志。它是容器stdout和stderr写入的地方。