In order to monitor memory and disk usage, you need to install Cloudwatch agent in the EC2 instance.
Create IAM role > CloudWatchAgentServerPolicy > and attach it to the instance
Add CloudWatchAgentAdminPolicy and AmazonEC2RoleforSSM
Access Windows server » Powershell
Download the installation file
1
Invoke-WebRequest -Uri "https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/AmazonCloudWatchAgent.zip" -OutFile "C:\AwsCloudWatchAgent.zip"
Unzip the file from C drive
Double click the exe file to install it.
Goto the installation folder:
1
C:\Program Files\Amazon\AmazonCloudWatchAgent
Open the file config.json (if there is no such file, create one)
Copy the following to the config.json file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
"metrics": {
"aggregation_dimensions": [
[
"AutoScalingGroupName"
]
],
"append_dimensions": {
"AutoScalingGroupName": "${aws:AutoScalingGroupName}",
"ImageId": "${aws:ImageId}",
"InstanceId": "${aws:InstanceId}",
"InstanceType": "${aws:InstanceType}"
},
"metrics_collected": {
"LogicalDisk": {
"measurement": [
"% Free Space"
],
"metrics_collection_interval": 60,
"resources": [
"*"
]
},
"Memory": {
"measurement": [
"% Committed Bytes In Use"
],
"metrics_collection_interval": 60
}
}
}
}
Execute the following command from powershell
1
2
cd C:\Program Files\Amazon\AmazonCloudWatchAgent
.\amazon-cloudwatch-agent-ctl.ps1 -a fetch-config -m ec2 -c file:'C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json' -s
Once done, wait for few minutes. The disk and memory usage will be available at AWS account » CloudWatch » Metrices » CWAgent » AutoScalingGroupName
Create Cloudwatch alarm by selecting any of the metrics.
That’s it!