Easy: How To Setup Amazon CloudWatch Agent

Easy: How To Setup Amazon CloudWatch Agent

Use Amazon CloudWatch Agent to Monitor Capacity on Windows Instances in AWS.

Over the last couple of weeks there has been an increasing amount of noise; about either people unable to login to a server or capacity being close to the limit. The issue observed was that this required manual efforts to note when the issue was occuring.

Having in excess of 40 servers to keep an eye on, it’s not ideal to wait until it’s too late to tackle the problem. With this issue we know that we want to be proactive. Tackle the issue way before it even starts to become an issue.

When looking at instances on AWS, there is no data by default to detail the storage space available on the drive.

Amazon CloudWatch Agent

How can we get to a point where we can preemptively flag this issue before it comes a problem without big overheads? Luckily Amazon provide a tool called CloudWatch Agent. It’s a small tool which you can install and configure on your server and instantly get reports back to CloudWatch.

CloudWatch Agent Installation

When you go to the CloudWatch Agent page you’ll see there is tooling for any number of servers you might have running. In this case we’re working on a Windows Server. The best tool for this will be under the Windows Platform. At this point just download the .msi file directly onto the server.

After the file has been downloaded the next step is to run the installation file which will run through. You should expect to see the following folders created.

  • C:\Program Files\Amazon\AmazonCloudWatchAgent
  • C:\ProgramData\Amazon\AmazonCloudWatchAgent

Configure the tool

After the application has been installed it’ll need to be configured to detail which data we want to send back to CloudWatch.

Location the config wizard: C:\Program Files\Amazon\AmazonCloudWatchAgent\Amazon-CloudWatch-Agent-Config-Wizard.exe

To run the config ensure it’s launched as Administrator, otherwise the application will just close off.

The wizard is going to ask some questions to produce a json config file as we’re only after getting the servers capacity below is the config I ran. Although this can be changed to suit your needs.

Which OS are you planning to use the agent?
Trying to fetch the default region based on the ec2 metadata
Do you have any existing CloudWatch Log Agent Configuration file to import for migration?
Do you want to monitor any host metrics?
Do you want to monitor cpi metrics per core?
Do you want to add ec2 dimensions?
Would you like to collect your metrics at high resolution?
Which default metrics config do you want?

As seen above there are 4 different metric types you can choose from here is a table that details each one.

Detail levelMetrics included
BasicMemory: Memory % Committed Bytes In UseLogicalDisk: LogicalDisk % Free Space
StandardMemory: Memory % Committed Bytes In UsePaging: Paging File % UsageProcessor: Processor % Idle TimeProcessor % Interrupt TimeProcessor % User TimePhysicalDisk: PhysicalDisk % Disk TimeLogicalDisk: LogicalDisk % Free Space
AdvancedMemory: Memory % Committed Bytes In UsePaging: Paging File % UsageProcessor: Processor % Idle TimeProcessor % Interrupt TimeProcessor % User TimeLogicalDisk: LogicalDisk % Free SpacePhysicalDisk: PhysicalDisk % Disk TimePhysicalDisk Disk Write Bytes/secPhysicalDisk Disk Read Bytes/secPhysicalDisk Disk Writes/secPhysicalDisk Disk Reads/secTCP: TCPv4 Connections EstablishedTCPv6 Connections Established

Once default metrics has been selected the tooling will show the current output of the config file.

Shown config
Are you satisfied with the above config?
Do you want to modify any customised log files?
Do you want to monitor any Windows event logs?
Do you want to store the config in the SSM parameter store?

Launch CloudWatch Agent

Once the config file has been setup you should be able to locate the file at:

C:\Program Files\Amazon\AmazonCloudWatchAgent\

Next launch the tooling, open an Admin session for PowerShell and enter the following code.

& "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c file:"C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json"

This application will now show up in Task Manager

Amazon CloudWatch Agent Task Manager

After 30 seconds we should now be able to go into CloudWatch and create and alarm or Dashboard to show this data.

Setup CloudWatch Dashboard

Log into AWS and go to CloudWatch create a new Dashboard give it a nice fancy name, obviously something that makes it easy to understand what it refers to.

Next add a widget and select Number.

Within the search metrics look for ‘Logical‘ this is sensitive or typing Logic or anything similar won’t work the same. Select “Host, instance, objectname“. Then we should see the server the Amazon CloudWatch Agent was installed on. Select the server and click Create Widget.

This will get added to the dashboard, don’t forget to save the Dashboard once it’s created or it’s updated.

After that it’s wise to get the information as an alarm as well, this reduces people overlooking the dashboard as a daily check. So go to All Alarms and Create Alarm.

Select your metric which is the same process of adding it to the dashboard.

Cloudwatch select metric

Search for ‘Logical‘ and again select the server which has the CloudWatch Agent installed on it.

Set the conditions you want, the threshold previously used is 90 which will display an alarm in the storage reaches over 90% used capacity. Click next to configure the output of the alert.

Create a new SNS topic, give it a name and then the destination can be set to an email address. In another post we’ll be discussing how to setup a lambda function so that alerts can be forwarded to Teams or another application.

Leave a Reply

Your email address will not be published.