Setting up CloudWatch with your Linux Instances on AWS

Document created by fadi.josef Expert on Jan 24, 2018Last modified by jacob.bendavid on Jan 29, 2019
Version 21Show Document
  • View in full screen mode

Turbonomic leverages MemoryUsed reported into CloudWatch. In this document, we cover how to configure AWS to capture memory stats in Turbonomic from your Linux EC2 instances using AWS Systems Manager. 

 

 If you are looking for the Windows version then you can find it here: Setting up CloudWatch for Windows

 

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:
    • AmazonEC2RoleforSSM
    • CloudWatchFullAccesss
    • AMAzonSSMFullAccess 

 

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 on Actions>Instance Settings>Attach/Replace IAM role. Then select the IAM role with the required permissions and  clickApply (see example below).

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

 

Note, if you need a scripted approach to add the IAM role to multiple instances please contact Turbonomic Support. 

 

Installing CloudWatch Agent on your Linux Instances

  • Navigate to the EC2 service under the account and region you'd like to configure  
  • In the navigation pane, under Systems Manager Services, choose Run Command.
  • In the Command document list, choose AWS-ConfigureAWSPackage
  • 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 end, you should see the status saying Success 

Create the Agent Configuration

The CW Agent will be configured to define which metric(s) are being sent to a CW Namespace, and other data required.  The following json represents the minimum requirements and cannot be changed.  By default, this configuration will store 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}"

    }

  }

}

In addition, you can configure optional parameters of the CW 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 at this time. Refer to AWS Documentation for more details.

Creating Parameter Store

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

  • Navigate  the EC2 service under the account and region you'd like to configure  
  • In the navigation pane, choose Parameter Store
  • If you don't have any Parameter Store then you will see the Welcome Screen. Click on Get Started Now
  • Copy and paste the json agent configuration you created in the above step into the Value field (also attached below)

  • Under the Name field, you can enter anything but I chose CloudWatchLinux
  • Now click Create Parameter

Now you should see a message saying it has been created.

Once you click Close you should the Parameter created

Deploying CloudWatch Configuration File

  • In the navigation pane, choose Run Command.
  • Click on Run Command once the page loads up 
  • In the Command document list, choose AmazonCloudWatch-ManageAgent
  • In the Targets area, choose the instance or multiple instances on which you want to deploy CloudWatch Configuration on
  • Under Action select configure 
  • Under Mode leave it as ec2
  • Change the Optional Configuration Source to ssm
  • Under Optional Configuration Location enter the exact 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 will restart the CloudWatch agent, not the instance)
  • Now click on Run

In the end, you should see something like this. 

 

Contributors

  • Eva Tuczai
  • Ben Yemini
  • Jacob Ben-David

References  

4 people found this helpful

Attachments

Outcomes