14

I want to make alarm in case that there is 10% left in my disk space.

I read some articles of how monitoring free disk space with Cloud Watch but I think it seems to be only for linux.

Do you have any solution for monitoring free disk space for windows?

Thanks in advance.

Misha Zaslavsky
  • 8,414
  • 11
  • 70
  • 116
  • 1
    You can read [here](https://blogs.aws.amazon.com/application-management/post/Tx1KG4IKXZ94QFK/Using-CloudWatch-Logs-with-Amazon-EC2-Running-Microsoft-Windows-Server) and [here](http://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/UsingConfig_WinAMI.html#configure_log_flow) – Frederic Henri May 25 '16 at 15:43
  • 2
    @FrédéricHenri That first link is about CloudWatch Logs, not metrics. How would you monitor the free disk space using that? I also don't see anything about disk space monitoring in your second link. – Mark B May 25 '16 at 16:07
  • read the part about _Performance Counters_ : "In addition to log data, you can also send Windows Performance Counters to CloudWatch as custom metrics. This makes it possible to monitor specific performance indicators from inside an instance and allows you to create alarms based on this data." "Add an additional performance counter to this – the amount of free space available on the C drive on the instance" it will sent those metrics to cloud watch – Frederic Henri May 25 '16 at 17:09
  • You can install scollector and collect you host metrics this way, unless you want these disk metrics specifically in CloudWatch? – Sergei Rodionov May 25 '16 at 19:13
  • You can use the CloudWatch agent, please check this answer: https://stackoverflow.com/a/62045062/3478220 – numX Nov 08 '20 at 20:52

4 Answers4

15

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

Simon Hutchison
  • 2,949
  • 1
  • 33
  • 32
  • Howdy Simon, I've been looking through some other posts and just watched your linked video. Do you have to fiddle with access / IAM role settings to report these metrics? I.e. Creating an IAM user and adding Access/Secret keys to "CloudWatch" in the JSON you've referred to? – Lovethenakedgun Jun 12 '18 at 06:42
  • @user3577502 I'm not aware of any requirement to configure IAM. – Simon Hutchison Jun 13 '18 at 00:46
9
  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.
Kai-Rune
  • 462
  • 6
  • 17
InvulgoSoft
  • 3,231
  • 1
  • 16
  • 6
  • I have posted a question related to this. Please check it out. [http://stackoverflow.com/questions/41512069/unable-to-monitor-free-disk-space-for-windows-instances-using-custom-cloudwatch] – prudhvi Jan 06 '17 at 19:01
2

In Windows EC2 instance (tested on Server 2019) Download and install CloudWatch Agent based on your instance type.

AWS CloudWatch Agent Installation

After that you'll notice a new service called Amazon CloudWatch Agent: it won't start until you configure it.

To configure that run the wizard located at C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-config-wizard.exe

Answer to all questions (you can skip log analysis and choos Basic metric for free storage percentage) and eventually a file called config.json will be created at C:\Program Files\Amazon\AmazonCloudWatchAgent

Move this file to C:\ProgramData\Amazon\AmazonCloudWatchAgent, rename it as amazon-cloudwatch-agent.json and start the service Cloudwatch Agent.

The service should start and collect metrics,check the log to see if there's are any error

If in log located at C:\ProgramData\Amazon\AmazonCloudWatchAgent\Logs you see this...

2020/05/27 16:11:27 I! Config has been translated into TOML C:\ProgramData\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent.toml 2020-05-27T14:11:31Z I! cloudwatch: get unique roll up list [] 2020-05-27T14:11:31Z I! Starting AmazonCloudWatchAgent 2020-05-27T14:11:31Z I! Tags enabled: host=[your host] 2020-05-27T14:11:31Z I! Agent Config: Interval:1m0s, Quiet:false, Hostname:[your host], Flush Interval:1s 2020-05-27T14:11:31Z I! cloudwatch: publish with ForceFlushInterval: 1m0s, Publish Jitter: 23s 2020-05-27T14:11:31Z I! Started the statsd service on :8125 2020-05-27T14:11:31Z I! Statsd listener listening on: [::]:8125

...all's gone well, as long as you have attached a IAM role to your instance to give it permissions to report to cloudwatch.

See this: CloudWatch permissions

Then you can find all your new defined metrics at CWAgent Parameters section in Cloudwatch, so that you can create an alarm

BR1COP
  • 321
  • 2
  • 5
0

I think the basic question is for setting up the disk utilization alarm in CloudWatch for Windows instance. I hope you know that to get the disk metrics in CloudWatch you need to install the CloudWatch agent, which involves multiple steps already people have mentioned above. We get the %age of free space for Windows instance from AWS CloudWatch agent. So to set the alarm for high disk utilization we need to select alarm condition as lower than or equal to 10% or as per your requirement. I hope this answers your question.alarm condition for windows disk