IBM Support

Setting up CloudWatch Memory Metrics on Linux Instances on AWS

How To


Summary

Turbonomic leverages MemoryUsed reported into CloudWatch. This document covers configuring the AWS CloudWatch agent to capture Linux EC2 MemoryUsed stats in Turbonomic by leveraging AWS Systems Manager.

Steps

Prerequisites:

  • AWS SSM Agent Installed on EC2
    • Linux image already has the SSM Agent installed. Linux SSM Agent is now installed by default on Amazon Linux AMIs dated 2017.09 and later. You would only need to manually install SSM Agent on other versions of Linux, as described in this article .
  • IAM Role with the following permissions: AmazonSSMFullAccess 

      Note: The least privilege permissions needed for the IAM role are AmazonEC2RoleforSSM (a custom policy to allow       the action "ssm:GetParameter" to the resource "arn:aws:ssm:*:*:parameter/*", see JSON  example)

Attach IAM Role

To configure each Linux EC2 instance through System Manager, you need to attach an IAM role with the above permissions to each EC2 instance.  

  • Select the EC2 instance and click Actions>Instance Settings>Attach/Replace IAM role. Then, select the IAM role with the required permissions and click apply (see example below).
    image-20230501164555-2

Now you should see the role attached to the EC2 instance (see Turbo_CW below)

 image-20230501164513-1

Installing CloudWatch Agent on your Linux Instances

  • Navigate to the 'System Manager' service under the account and region you'd like to configure  
  • In the navigation pane, choose Run Command and then click Run a Command:
    image-20230501164645-3
  • In the Command document list, choose AWS-ConfigureAWSPackage
    image-20230501164719-4
  • In the Targets area, choose the instance or multiple instances on which to install the CloudWatch agent. If you do not see a specific instance, it might not be configured for Run Command.
  • In the Action list, choose Install.
  • In the Name field, type AmazonCloudWatchAgent
  • Leave Version set to latest to install the latest version of the agent.
  • Choose Run. In the next screen, you should see a confirmation message that the command was sent successfully and the status should be Success after few seconds
    image-20230501164758-5

Create the Agent Configuration

The CloudWatch agent is configured to define which metrics are being sent to a CloudWatch Namespace, and other data required.  The following JSON represents the minimum requirements and cannot be changed.  By default, this configuration stores the metrics in the region in which the VM exists.

This will be used in the next step. 

{

      "agent": {

        "metrics_collection_interval": 60,

        "logfile": "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"

      },

"metrics": {

    "metrics_collected": {

      "mem": {

        "measurement": [

          {"name": "used", "rename": "MemoryUsed"},

          {"name": "mem_available", "rename": "MemoryAvailable"}

        ]

        }

      },

    "append_dimensions": {

      "InstanceId": "${aws:InstanceId}"

    }

  }

}

Also, you can configure optional parameters of the CloudWatch namespace (CWAgent is the default when not defined), and region (default region where data is located in the region where the instance runs).  Note adding more metrics to be collected will not be reflected in Turbonomic – only Used Memory will be collected currently. Refer to AWS Documentation for more details.

Creating Parameter Store

Now you need to create a parameter store for the above configuration so it can be deployed across multiple EC2 instances 

  • Navigate to the 'System Manager' service under the account and region you'd like to configure  
  • In the navigation pane, choose Parameter Store and then click Create Parameter
    image-20230501164834-6
  • Copy and paste the JSON agent configuration you created in the above step into the Value field (leave all options at default)
    image-20230501164904-7
    image-20230501164928-8
  • Under the Name field, you can enter any name, but you must use the same name in the next step, for example, we used CloudWatchLinux
  • Now click Create Parameter -  you should see a message saying it has been created and the parameter listed 
    image-20230501164959-9

Deploying The CloudWatch Configuration File

  • In the 'System Manager' navigation pane, choose Run Command and then click Run a Command
  • In the Command document list, choose AmazonCloudWatch-ManageAgent
  • Under Action select configure 
  • Under Mode leave it as ec2
  • Change the Optional Configuration Source to ssm
  • Under Optional Configuration Location, enter the same name of the parameter you created in the Parameter Store (previous section). In this example, the parameter is called CloudWatchLinux
  • Optional Restart should be set to Yes (This restart the CloudWatch agent, not the instance)
    image-20230501165023-10
  • In the Targets area, choose the instance or multiple instances on which you want to deploy CloudWatch Configuration
    image-20230501165100-11
  • Now click Run - In the end, you should see something like this.
    image-20230501165140-12

Installation complete

To confirm that the instance is sending the Memory Metrics, head to the CloudWatch page, click Metrics and locate the CWAgent namespace (Only be created if the process worked successfully), click InstanceId > there should be 2 Metrics per Linux instance, click 'MemeoryUsed' and confirm data is collected:
image-20230501165208-13

Note it can take up to 30 minutes in some cases for Memory metric to show up in the Turbonomic user interface.

Document Location

Worldwide

[{"Type":"MASTER","Line of Business":{"code":"LOB45","label":"Automation"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSFV9Z","label":"IBM Turbonomic Application Resource Management"},"ARM Category":[{"code":"a8m3p000000PCLHAA4","label":"Public Cloud"}],"ARM Case Number":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]

Document Information

Modified date:
01 May 2023

UID

ibm16854417