我的Elastic Beanstalk环境正在阻止将node.js事件传输到CloudWatch Logs。 Streaming适用于新实例的视图分钟。查看分钟后,CloudWatch中不再显示任何日志。
我设置了AWS Elastic Beanstalk,以便在Configuration>下将日志流式传输到CloudWatch。软件配置> CloudWatch Logs> Log Streaming(true)。我停用了日志流并重新激活它作为测试。看看cloudwatch
每次运行状况检查都会将每个视图的日志条目写入nodejs.log。
我没有在ec2实例上找到有关日志流的任何日志。
---编辑
[ec2-user@ip-###-##-##-## log]$ cat /var/log/awslogs.log
2017-03-07 11:01:05,928 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Detected file rotation, notifying reader
2017-03-07 11:01:05,928 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Reader is still alive.
2017-03-07 11:01:05,928 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:05,928 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:06,052 - cwlogs.push.reader - INFO - 31861 - Thread-8 - No data is left. Reader is leaving.
2017-03-07 11:01:10,929 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Removing dead reader [2177a5cce5ed29525de329bfdc292ff1, /var/log/nginx/access.log]
2017-03-07 11:01:10,929 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Starting reader for [92257964a10edeb586f084f4f2ba35de, /var/log/nginx/access.log]
2017-03-07 11:01:10,930 - cwlogs.push.reader - INFO - 31861 - Thread-11 - Start reading file from 0.
2017-03-07 11:01:10,930 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:10,930 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:15,931 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:15,931 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:16,788 - cwlogs.push.publisher - INFO - 31861 - Thread-7 - Log group: /aws/elasticbeanstalk/production/var/log/nginx/access.log, log stream: i-0bd24767864801e2c, queue size: 0, Publish batch: {'skipped_events_count': 0, 'first_event': {'timestamp': 1488884470930, 'start_position': 0L, 'end_position': 114L}, 'fallback_events_count': 0, 'last_event': {'timestamp': 1488884472931, 'start_position': 341L, 'end_position': 454L}, 'source_id': '92257964a10edeb586f084f4f2ba35de', 'num_of_events': 4, 'batch_size_in_bytes': 554}
2017-03-07 11:01:20,932 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:20,932 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:25,933 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:25,933 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:27,881 - cwlogs.push.publisher - INFO - 31861 - Thread-7 - Log group: /aws/elasticbeanstalk/production/var/log/nginx/access.log, log stream: i-0bd24767864801e2c, queue size: 0, Publish batch: {'skipped_events_count': 0, 'first_event': {'timestamp': 1488884481933, 'start_position': 454L, 'end_position': 568L}, 'fallback_events_count': 0, 'last_event': {'timestamp': 1488884482934, 'start_position': 568L, 'end_position': 681L}, 'source_id': '92257964a10edeb586f084f4f2ba35de', 'num_of_events': 2, 'batch_size_in_bytes': 277}
答案 0 :(得分:0)
Andrew(@ andrew-ferk)和我自己激活日志流时,它使用当前日志在CloudWatch中创建了所有日志组和流。再次部署后,我们注意到日志已停止。这是因为aws哈希了日志的第一行。如果在看到哈希之前,它将像对待文件一样对待该文件
如果您使用的是npm start
,则第一行将是您应用程序的版本名称。
您可以在您的dockerfile中添加CMD date && npm start
来每次触发不同的第一行,或者以静默方式运行npm(只要您的第一个输出是唯一的)。
另外,根据他们的文档,您应该在启用功能AWS-Docs
之前向Elastic-Beanstalk添加一些策略。{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:GetLogEvents",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
"logs:PutRetentionPolicy"
],
"Resource": [
"*"
]
}
]
}
答案 1 :(得分:0)
以下常见问题解答可能会有所帮助:
要检查是否正在流式传输自定义日志文件的一些事情:
eb ssh
进入实例并查看/var/log/awslogs.log
。如果这还没有提到“从(从您的awslogs配置文件)加载其他配置”,请确保安装正确的配置文件以及安装后重新启动awslogs服务(大概使用.ebextensions
。请参阅“ Using Elastic Beanstalk with Amazon CloudWatch Logs中的“自定义日志文件流”。有关如何重新启动awslogs服务,请参见logs-streamtocloudwatch-linux.config中的commands
部分。file_fingerprint_lines
。参见CloudWatch Logs Agent Reference。