CloudWatch users may have requirements to send custom metrics. These metrics can be server-based or application-based. CloudWatch can be notified in a number of ways. One way is to write a PowerShell script that will run periodically and schedule it in Task Scheduler. An alternative way to achieve this, which I find very simple, is to make small changes in EC2ConfigService within your windows instance.
ADVANTAGES:
It is easy to put into practice.
It is not necessary to write lengthy scripts.
Task Scheduler is not necessary, which can help to save memory.
Most importantly, the margin of error is very small.
Let’s say you want to send CloudWatch free disk and memory usage metrics.
PREREQUISITES:
EC2Config version 2.2.5 or higher should be used.
Create an IAM user with the following permissions.
“Version”: “2012-10-17”, “Statement”: [ “Sid”: “AllowAccessToSSM”, “Effect”: “Allow”, “Action”: [ “cloudwatch:PutMetricData”, “logs:CreateLogGroup”, “logs:CreateLogStream”, “logs:DescribeLogGroups”, “logs:DescribeLogStreams”, “logs:PutLogEvents” ], “Resource”: [ “*” ] ]1234567891011121314151617181920″Version”: “2012-10-17″,”Statement”: [“Sid”: “AllowAccessToSSM”,”Effect”: “Allow”,”Action”: [“cloudwatch:PutMetricData”,”logs:CreateLogGroup”,”logs:CreateLogStream”,”logs:DescribeLogGroups”,”logs:DescribeLogStreams”,”logs:PutLogEvents”],”Resource”: [“*”]]
IMPLEMENTATION:
1. RDP into your windows instance. Click the Start menu and click All Programs. Then click EC2ConfigService settings. Click OK to enable CloudWatch Logs Integration.
3. Go to C:Program FilesAmazonEc2ConfigServiceSettingsAWS.EC2.Windows.CloudWatch.json and replace below code in the file.
“EngineConfiguration”: “PollInterval”: “00:00:15”, “Components”: [ “Id”: “PerformanceCounterMemory”, “FullName”: “AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch”, “Parameters”: “CategoryName”: “Memory”, “CounterName”: “Available MBytes”, “InstanceName”: “”, “MetricName”: “Memory”, “Unit”: “Megabytes”, “DimensionName”: “InstanceId”, “DimensionValue”: “instance_id” , “Id”: “PerformanceCounterDisk”, “FullName”: “AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch”, “Parameters”: “CategoryName”: “LogicalDisk”, “CounterName”: “Free Megabytes”, “InstanceName”: “C:”, “MetricName”: “FreeDisk”, “Unit”: “Megabytes”, “DimensionName”: “InstanceId”, “DimensionValue”: “instance_id” , “Id”: “CloudWatch”, “FullName”: “AWS.EC2.Windows.CloudWatch.CloudWatch.CloudWatchOutputComponent,AWS.EC2.Windows.CloudWatch”, “Parameters”: “AccessKey”: “xxxxxxxxxxxxxxxxxxxx”, “SecretKey”: “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”, “Region”: “us-east-1”, “NameSpace”: “Windows/Default” ], “Flows”: “Flows”: [ “(PerformanceCounterMemory,PerformanceCounterDisk),CloudWatch” ] 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950{“EngineConfiguration”: {“PollInterval”: “00:00:15″,”Components”: [{“Id”: “PerformanceCounterM