amazon-web-services - 为 cloudwatchLogs 中的每个日志文件创建一个 logStream

标签 amazon-web-services amazon-ec2 configuration stream amazon-cloudwatchlogs

我用 AWS CloudWatch日志代理将我的应用程序日志推送到 AWS Cloudwatch。

cloudwatchLogs我的 EC2 instance 中的配置文件,我有这个条目:

[/scripts/application]
datetime_format = %Y-%m-%d %H:%M:%S
file = /workingdir/customer/logfiles/*.log
buffer_duration = 5000
log_stream_name = {instance_id}
initial_position = start_of_file
log_group_name = /scripts/application

根据此配置,workingdir 目录中的所有日志文件都将发送到同一流中的 cloudwatchLogs,名称为实例 ID。

我的问题是,我想为每个日志文件创建一个单独的 logStream ,让日志读取更快速、更易解析 .换句话说,每次我有一个新的日志文件时,都会自动创建一个新的日志流。

我想通过 cron 作业中的 shell 脚本来做到这一点,但随后我必须更改架构中的许多其他配置,因此我正在寻找一种在配置文件中执行此操作的方法。在文档中,他们说:

log_stream_name

Specifies the destination log stream. You can use a literal string or predefined variables ({instance_id}, {hostname}, {ip_address}), or combination of both to define a log stream name. A log stream is created automatically if it doesn't already exist.



日志文件的名称不能 100% 可预测,但它们始终具有以下结构:
CustomerName-YYYY-mm-dd.log

此外,另一个问题是:

A running agent must be stopped and restarted for configuration changes to take effect.



在这种情况下如何设置 logStream?

非常感谢任何想法或建议或解决方法。

最佳答案

我知道现在已经快两年了,但我想做完全相同的事情并且找不到让它工作的方法。
我求助于 AWS Support,然后确认这无法完成。我们仅限于文档中提供的选项,就像您发布的一样。但是,您可以拥有 日志组 包含直到第一个点的日志文件路径:

log_group_name – Optional. Specifies what to use as the log group name in CloudWatch Logs. Allowed characters include a-z, A-Z, 0-9, '_' (underscore), '-' (hyphen), '/' (forward slash), and '.' (period).

We recommend that you specify this field to prevent confusion. If you omit this field, the file path up to the final dot is used as the log group name. For example, if the file path is /tmp/TestLogFile.log.2017-07-11-14, the log group name is /tmp/TestLogFile.log.



https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html

关于amazon-web-services - 为 cloudwatchLogs 中的每个日志文件创建一个 logStream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42924765/

相关文章:

android - 在 AWS IOT 中调用 getShadow/updateShadow 时出现 ForbiddenError 403

python - AWS IoT Python SDK 和 asyncio

amazon-web-services - Cloud Formation 模板将入口规则添加到现有安全组

dictionary - Golang 映射 YAML 对象

amazon-web-services - 如何将 DynamoDb 迁移到 RDS (Aurora)

amazon-web-services - AWS Step Functions : it doesn't show list of existing roles while creating a new state machine

amazon-web-services - CloudWatch 自定义 EC2 内存指标和带有 AutoScaling 策略的警报

php - Slim 之外的 Slim 框架配置

django - 运行PyCharm测试时,如何解决“django.core.exceptions.ImproperlyConfigured:找不到GDAL库”?

java - 我如何从 aws cloudwatch 的特定指标中获取数据?