Setting up CloudWatch Agent on AWS EC2

Setting up CloudWatch Agent on AWS EC2

This guide describes how to set up AWS CloudWatch Agent in CloudXper.

This setting allows you to check Memory Utilization in CloudXper.

AWS CloudWatch Agent Configuration Guide

How CloudXper Collects Memory Metrics

  • AWS does not provide memory-related metrics as default metrics.

  • You must install CloudWatch on EC2 to view Memory metrics.

  • When CloudXper receives the Memory metrics, Based on InstanceIdIt can only be received as (Dimension = InstanceId).

  • Metrics to collect

    • Linux: “mem_used_percent”

    • Window: “Memory % Committed Bytes In Use”

Setup Guide

  • CloudWatch Agent Config settings required

  1. Modify the Config Default file (the path may vary depending on your OS, so check it)
    Modify the /opt/aws/amazon-cloudwatch-agent/amazon-cloudwatch-agent.d/default file (sudo permission required)

    1. Linux

      1. If you need to view data by combination of InstanceId, ImageId, InstanceType, and AutoscalingGroupName, modify as follows:

        { "agent": { "run_as_user": "cwagent" }, "metrics": { "metrics_collected": { "mem": { "measurement": [ "mem_used_percent" ] }, "disk": { "measurement": [ "used_percent" ], "resources": [ "*" ] } }, "append_dimensions": { "ImageId": "${aws:ImageId}", "InstanceId": "${aws:InstanceId}", "InstanceType": "${aws:InstanceType}", "AutoScalingGroupName": "${aws:AutoScalingGroupName}" }, "aggregation_dimensions": [ [ "InstanceId" ], [ "InstanceId", "ImageId", "InstanceType", "AutoScalingGroupName" ] ] } }

         

      2. If you only want to view data in CloudXper, modify it as follows:

        {     "agent": {         "run_as_user": "cwagent"     },     "metrics": {         "metrics_collected": {             "mem": {                 "measurement": [                     "mem_used_percent"                 ]             },             "disk": {                 "measurement": [                     "used_percent"                 ],                 "resources": [                     "*"                 ]             }         },         "append_dimensions": {             "InstanceId": "${aws:InstanceId}"         }     } }

         

    2. Window

      1. To-BE Write

  2. Stop the CloudWatch agent

    1. sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a stop

  3. Starting the CloudWatch agent

    1. sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a start

  4. Check CloudWatch agent status

    1. sudo /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -m ec2 -a status

    2. If it appears as below, it is normal

    {     "status": "running",     "starttime": "시작시간",     "configstatus": "configured",     "cwoc_status": "stopped",     "cwoc_starttime": "",     "cwoc_configstatus": "not configured",     "version": "1.247347.3b250378" }

     

  5. Confirm actual collection

    1. If it exists in the CWAgent Namespace, it is normal.

      image-20250203-020406.png
    2. If you see a part that is only searched by InstanceId, it is normal.

      image-20250203-020448.png
    3. If you see Memory Data, it's normal

      image-20250203-020801.png