Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for collecting memory usage using CloudWatch agent #154

Open
tschaub opened this issue Sep 29, 2021 · 2 comments
Open

Example for collecting memory usage using CloudWatch agent #154

tschaub opened this issue Sep 29, 2021 · 2 comments

Comments

@tschaub
Copy link

tschaub commented Sep 29, 2021

I've been struggling to configure an Elastic Beanstalk application to generate metrics on memory usage. In this repo, I've found the autoscaling-memory-utilization.config, and that seems to have the required parts. I've been having trouble getting it to work ("ERROR: Cannot obtain instance id from EC2 meta-data.") and found a doc on monitoring scripts that say they are deprecated. It sounds like the alternative is to "use the CloudWatch agent to collect metrics and logs."

Is there a complete example of how to use the CloudWatch agent to monitor memory use on Elastic Beanstalk instances? I'm not clear on the difference between CloudWatch agent and CloudWatch Logs agent, but I see that the latter is on the path to deprecation.

@tschaub
Copy link
Author

tschaub commented Sep 29, 2021

Maybe I should add that on my EC2 instances, I already see configuration files in /opt/aws/amazon-cloudwatch-agent/etc/. So I guess I'm looking for a way to extend whatever configuration is there with memory metrics collection configuration.

@tschaub
Copy link
Author

tschaub commented Sep 30, 2021

It looks like it is possible to append a CloudWatch agent configuration with amazon-cloudwatch-agent-ctl. I was able to successfully deliver memory use related metrics to CloudWatch by adding a .platform/confighooks/postdeploy/configure-cloudwatch-agent.sh script that looks like this:

#!/usr/bin/env bash
set -e

cat >/tmp/cloudwatch-agent-custom-config.json <<EOL
{
  "metrics": {
    "metrics_collected": {
      "mem": {
        "measurement": [
          "mem_used_percent"
        ],
        "metrics_collection_interval": 1
      }
    }
  }
}
EOL

amazon-cloudwatch-agent-ctl \
  -a append-config \
  -m ec2 \
  -c file:/tmp/cloudwatch-agent-custom-config.json \
  -s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant