Skip to content

How to optimize the Cloudwatch logs ?

0

We use Cloudwatch logs for debugging and any errors are notified by Metrics. We are not heavily depedent on CW logs.

Our Cloudwatch logs are high even after taking below steps 2. 1. We started logging minimal as possible. 2. We have set log retention to 1 month. 3. Exploring option for Infrequent Log access.

I have following questions

  1. We also emit CW Metrics (not inferred from logs), does these metrics also contribute for cloudwatch logs ?
  2. Is there a way to buffer more than 32 KB log size in Cloudwatch log agent ? [Would adding more buffer help here]

asked a year ago451 views

2 Answers
0

Hello,

In this context, I have addressed your queries below-



  1. We also emit CW Metrics (not inferred from logs), does these metrics also contribute for cloudwatch logs ?

No, the CloudWatch Metrics you emit separately do not contribute to the CloudWatch Logs size or usage. CloudWatch Metrics and CloudWatch Logs are separate services, and the data sent to each does not overlap. Metrics capture numerical data points, while logs capture textual data. So your custom CW Metrics would not add to the volume of your CloudWatch logs.

  1. Is there a way to buffer more than 32 KB log size in Cloudwatch log agent ? [Would adding more buffer help here] buffer_duration specifies the time duration for the batching of log events. The minimum value is 5000ms and default value is 5000ms.

Yes, it is possible to buffer more than 32 KB in the CloudWatch Logs agent, and doing so can be beneficial in certain situations. The CloudWatch Logs agent allows for configurable buffer sizes, and increasing the buffer can help prevent log streaming from stopping due to long-running processes or high log volumes.

For ECS Fargate tasks, you can increase the buffer size using the awslogs-buffered-data-mb setting in the task definition. For EC2 instances using the CloudWatch agent, you can modify the buffer settings in the agent configuration file. In order to increase the buffer size, you need to modify the CloudWatch agent configuration file. For example, on Linux servers, this file is typically located at /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json. You can adjust the buffer_duration and batch_size parameters in the configuration.

That being said, if you would like resource based Information/troubleshooting, please raise a support case with AWS for further information. If a support case has already been created please be assured that we will get back to you and assist you in the best way possible.

AWS

answered a year ago

  • Is there a documentation to explain the fields in '/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.json' and maximum value which could be set for the fields buffer_duration and batch_size

0

Based on your situation, here are some additional ways to optimize CloudWatch Logs costs:

Regarding your specific questions:

  1. CloudWatch Metrics and CloudWatch Logs are separate services with different pricing models. The metrics you emit directly do not contribute to your CloudWatch Logs costs. They are billed separately under CloudWatch Metrics pricing.

  2. For ECS Fargate tasks, you can increase the log buffer size by configuring the awslogs-buffered-data-mb setting in your task definition. This allows more data to be buffered before being sent to CloudWatch, which can help with long-running processes where log streaming might otherwise stop. For EC2 instances using the CloudWatch agent, you can adjust buffer settings in the agent configuration file.

Additional optimization strategies:

  • Consider sending logs directly to S3 instead of CloudWatch Logs for certain log types. For example, CloudTrail logs and VPC flow logs can be configured to go directly to S3, bypassing CloudWatch Logs ingestion costs entirely.

  • Use the CloudWatch agent with log filter expressions to collect only the log events that meet your specific criteria, reducing the volume of logs sent to CloudWatch.

  • For application logs, choose an efficient log syntax that minimizes verbosity while still providing necessary information.

  • Run queries from your CloudWatch Logs Insights history to reduce analysis costs.

  • Since you mentioned you're not heavily dependent on CloudWatch Logs and mainly use them for debugging with metrics for notifications, Infrequent Access log class would be a good fit for your use case, as it offers fewer features but at a reduced price.

  • Review your top log groups by spend to identify specific areas where you can further optimize.
    Sources
    Analyzing, optimizing, and reducing CloudWatch costs - Amazon CloudWatch
    Lowering logs ingestion cost for CloudWatch logs | AWS re:Post
    ECS Task Logs Stop Streaming to CloudWatch After Long Runtime | AWS re:Post

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.