Skip to content

Instantly share code, notes, and snippets.

@yancyn
Last active September 22, 2022 14:17
Show Gist options
  • Save yancyn/47e84f8e87a5046f768a54fbe7645025 to your computer and use it in GitHub Desktop.
Save yancyn/47e84f8e87a5046f768a54fbe7645025 to your computer and use it in GitHub Desktop.
Monitor Memory Utilization on AWS EC2 Windows Instance

Monitor Memory Utilization on AWS EC2 Windows Instance

How to Enable Memory Monitor

  1. AWS Console > Intance > Action
  2. Attach IAM role to your instance.
  3. Attach policy > CloudWatchFullAccess + AmazonSSMFullAccess.
  4. Start Windows instance.
  5. Configure CloudWatch.json based on your requirement before Ec2Config service is started.
  • Configure your region i.e. if your instance at us-web-2b set to us-west-2.
  • Add your IAM access key and secret key under CloudWatch component.
  • Lastly, define the flow you want. i.e. PerformanceCounter,CloudWatch.
  1. Start Ec2Config service under services.
  2. Done.

Now you can wait for 15 mins to sync the log to CloudWatch and you now can create any type of alarm alert you want.

Create Alarm

  1. Action > CloudWatch
  2. Pick Windows/Default metrics under available Metrics.
  3. Add alarm.
  4. Done.

Enjoy :-)

see Amazon Simple Notification Service Pricing

C:\Program Files\Amazon\Ec2ConfigService\Settings\AWS.EC2.Windows.CloudWatch.json

PollInterval in format HH:MM:SS.

{
    "EngineConfiguration": {
        "PollInterval": "00:00:15",
        "Components": [
            {
                "Id": "ApplicationEventLog",
                "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "LogName": "Application",
                    "Levels": "1"
                }
            },
            {
                "Id": "SystemEventLog",
                "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "LogName": "System",
                    "Levels": "7"
                }
            },
            {
                "Id": "SecurityEventLog",
                "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                "LogName": "Security",
                "Levels": "7"
                }
            },
            {
                "Id": "ETW",
                "FullName": "AWS.EC2.Windows.CloudWatch.EventLog.EventLogInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "LogName": "Microsoft-Windows-WinINet/Analytic",
                    "Levels": "7"
                }
            },
            {
                "Id": "IISLog",
                "FullName": "AWS.EC2.Windows.CloudWatch.IisLog.IisLogInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "LogDirectoryPath": "C:\\inetpub\\logs\\LogFiles\\W3SVC1"
                }
            },
            {
                "Id": "CustomLogs",
                "FullName": "AWS.EC2.Windows.CloudWatch.CustomLog.CustomLogInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "LogDirectoryPath": "C:\\CustomLogs\\",
                    "TimestampFormat": "MM/dd/yyyy HH:mm:ss",
                    "Encoding": "UTF-8",
                    "Filter": "",
                    "CultureName": "en-US",
                    "TimeZoneKind": "Local"
                }
            },
            {
                "Id": "PerformanceCounter",
                "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "CategoryName": "Memory",
                    "CounterName": "Available MBytes",
                    "InstanceName": "",
                    "MetricName": "Memory",
                    "Unit": "Megabytes",
                    "DimensionName": "",
                    "DimensionValue": ""
                }
            },
            {
                "Id": "CloudWatchLogs",
                "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatchLogsOutput,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "AccessKey": "",
                    "SecretKey": "",
                    "Region": "us-east-1",
                    "LogGroup": "Default-Log-Group",
                    "LogStream": "{instance_id}"
                }
            },
            {
                "Id": "CloudWatch",
                "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatch.CloudWatchOutputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": 
                {
                    "AccessKey": "",
                    "SecretKey": "",
                    "Region": "us-east-1",
                    "NameSpace": "Windows/Default"
                }
            }
        ],
        "Flows": {
            "Flows": 
            [
				"PerformanceCounter,CloudWatch"
            ]
        }
    } 
}

see https://stackoverflow.com/questions/41330555/monitoring-memory-usage-in-aws-cloudwatch-for-windows-instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment