15

我的 Elastic Beanstalk 环境正在停止将 node.js 事件流式传输到 CloudWatch Logs。流式处理在新实例上的视图分钟内工作正常。查看几分钟后,CloudWatch 中不再显示日志。

我设置 AWS Elastic Beanstalk 以在配置 > 软件配置 > CloudWatch 日志 > 日志流式处理 (true) 下将日志流式传输到 CloudWatch。我停用了日志流并将其重新激活为测试。看看云表

  • 上次 eb 活动日志大约 10 分钟前
  • 错误日志不可用(在两个实例上都没有)
  • nginx/access.log 是一个视图秒旧
  • nodejs.log 大约一个小时前(重新启动实例后不久)

不过,每次运行状况检查都会每隔查看秒数将一个日志条目写入 nodejs.log。

我没有在 ec2 实例上找到任何关于日志流的日志。

  1. 有没有人有类似的问题?
  2. 如何使 Elastic Beanstalk 将 nodejs 日志流式传输到 CloudWatch 日志。

- - 编辑

[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}
4

2 回答 2

1

Andrew (@andrew-ferk) 和我激活日志流时,它使用当前日志在 CloudWatch 中创建了所有日志组和流。再次部署后,我们注意到日志停止了。这是因为 aws 对日志的第一行进行哈希处理。如果它在处理该文件之前已经看到该哈希,则该文件已被处理

如果您使用npm start第一行将是您的应用程序的名称和版本。

您可以添加一个CMD date && npm start到您的 dockerfile 以每次触发不同的第一行或在静默模式下运行 npm(只要您的第一个输出是唯一的)。

同样根据他们的文档,您应该在启用AWS-Docs功能之前向您的弹性豆茎添加一些策略

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:GetLogEvents",
        "logs:PutLogEvents",
        "logs:DescribeLogGroups",
        "logs:DescribeLogStreams",
        "logs:PutRetentionPolicy"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
于 2019-03-13T01:31:53.027 回答
1

以下常见问题解答可能会有所帮助:

检查您是否正在流式传输自定义日志文件的一些事项:

  1. eb ssh进入实例并查看/var/log/awslogs.log. 如果这甚至没有提到“从(您的 awslogs 配置文件)加载其他配置”,请确保您正在安装正确的配置文件以及在安装后重新启动 awslogs 服务(大概使用.ebextensions。请参阅“自定义日志文件流式传输”在将 Elastic Beanstalk 与 Amazon CloudWatch Logs 结合使用。有关如何重新启动 awslogs 服务的信息,请参阅logs-streamtocloudwatch-linux.configcommands中的部分。
  2. CloudWatch Logs 代理是有状态的。如果日志文件的前几行是空白或从未更改,则可能需要设置file_fingerprint_lines. 请参阅CloudWatch Logs 代理参考
于 2019-04-12T13:04:33.423 回答