How to monitor free disk space at AWS EC2 with Cloud Watch in windows

时光怂恿深爱的人放手 提交于 2019-11-30 09:23:56

This is how to configure a Windows 2016 EC2 instance to report free disk space (or any other performance counter on your server)

  • Download a sample AWS.EC2.Windows.CloudWatch.json file. This is where I found one. https://s3.amazonaws.com/ec2-downloads-windows/CloudWatchConfig/AWS.EC2.Windows.CloudWatch.json

  • Copy the sample AWS.EC2.Windows.CloudWatch.json file on your Windows Server 2016 EC2 Instance here C:\Program Files\Amazon\SSM\Plugins\awsCloudWatch\

  • Edit AWS.EC2.Windows.CloudWatch.json and set IsEnabled true

  • Add additional metrics as required. There is a sample one in the config for memory usage. Copy/paste this and alter the Metric name like this:

{
    "Id": "PerformanceCounterDisk",
    "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
    "Parameters": {
        "CategoryName": "LogicalDisk",
        "CounterName": "% Free Space",
        "InstanceName": "C:",
        "MetricName": "FreeDiskPercentage",
        "Unit": "Percent",
        "DimensionName": "InstanceId",
        "DimensionValue": "{instance_id}"
    }
}
  • Run Powershell as administrator and run Restart-Service AmazonSSMAgent

  • New CloudWatch metrics appear almost instantly in AWS CloudWatch.

  • Configure AWS CloudWatch alarms as required.

Additionally, I made a short video with some tips on setting this up on Windows Server 2016.

https://www.youtube.com/watch?v=xKVrJJyG-4I

The following guide from AWS contains a step by step guide. http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/send_logs_to_cwl_instances.html#send_logs_cwl_configfile

InvulgoSoft
  1. Download and install the latest EC2Config to your windows instance (https://aws.amazon.com/developertools/5562082477397515)
  2. Edit the settings file here C:\Program Files\Amazon\Ec2ConfigService\Settings\AWS.EC2.Windows.CloudWatch.json

Insert some counters in the appropriate place

    {    
        "Id": "PerformanceCounterMemory",
        "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
        "Parameters": {
            "CategoryName": "Memory",
            "CounterName": "Available MBytes",
            "InstanceName": "",
            "MetricName": "Available-Memory",
            "Unit": "Gigabytes",
            "DimensionName": "InstanceId",
            "DimensionValue": "{instance_id}"
        }
    },
    {
        "Id": "PerformanceCounterDisk",
        "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
        "Parameters": {
            "CategoryName": "LogicalDisk",
            "CounterName": "% Free Space",
            "InstanceName": "C:",
            "MetricName": "FreeDiskPct",
            "Unit": "Percent",
            "DimensionName": "InstanceId",
            "DimensionValue": "{instance_id}"
        }
    }

Make sure to include them in the flow section:

"Flows": {
            "Flows": 
            [
                "(ApplicationEventLog,SystemEventLog),CloudWatchLogs",
                "(PerformanceCounterMemory,PerformanceCounterDisk),CloudWatch"
            ]
        }

Remember to set the key and secret of a user with cloudwatch policy rights.

  1. Restart the EC2Config service. Follow progress in the log: C:\Program Files\Amazon\Ec2ConfigService\Logs\Ec2ConfigLog.txt
  2. Create an alarm in cloudwatch on your new FreeDiskPct counter.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!