How to Use the CloudWatch Powershell Scripts to Monitor a Windows Instance

How to Use the CloudWatch Powershell Scripts to Monitor a Windows Instance

Amazon CloudWatch provides monitoring for AWS cloud resources and the applications customers run on AWS. Developers and system administrators can use it to collect and track metrics, gain insights, and immediate act to support a robust functioning of the applications and businesses.

The Amazon CloudWatch Monitoring Scripts for Linux and Windows demonstrate how to produce and consume the Amazon CloudWatch custom metrics. The scripts for Windows include sample PowerShell scripts, which comprise a fully functional example. The above mentioned example reports memory, page file, and disk space utilization metrics for an Amazon EC2 Windows instance.  Before you start make sure to install a Powershell script in the user’s windows instance.

This guide demonstrates how to use CloudWatch Powershell scripts to monitor the user’s Windows instance.

1. Launch a new Windows EC2  instance and connect to the instance.

2. Enter the Start Menu > Amazon Web Services and select Windows powershell for AWS.


[Newvem analyzes your baseline disaster recovery (DR) status, reflecting how well AWS DR best practices have been implemented, and recommends AWS features and best practices to reach optimal availability, increase outage protection, and quick recovery. Learn More]


3. In the Powershell command prompt, set the execution policy with the command “Set-ExecutionPolicy RemoteSigned”.

4. Set the AWS credentials for the Powershell scripts to access the user’s AWS account in the awscreds.conf file.

5. Powershell has three separate scripts to send the data -

a. mon-put-metrics-mem.ps1 – It collects the system metrics, such as memory, page file utilization of an Amazon EC2 Windows instance and sends them to the Amazon CloudWatch.

b. mon-put-metrics-disk.ps1 - It collects the system metrics, such as disk space utilization of an Amazon EC2 Windows instance and sends them to the Amazon CloudWatch.

c.  mon-put-metrics-perfmon.ps1 – It collects the system metrics, such as PerfMon counters of an Amazon EC2 Windows instance and sends them to the Amazon CloudWatch.

6. Execute each of the three separate scripts and check the data in the AWS CloudWatch.

7. First run the following command:

.\mon-put-metrics-mem.ps1 -aws_access_id <ACCESS KEY> -aws_secret_key <Secret Access Key> -mem_util -mem_avail -page_avail -page_used -page_util -memory_units kilobytes

Or

.\mon-put-metrics-mem.ps1 -aws_credential_file C:\AWS\AmazonCloudWatchMonitoringWindows\awscreds.conf -mem_util -mem_avail -page_avail -page_used -page_util -memory_units kilobytes

8. Once done a remote call will be initiated to the Amazon CloudWatch for reporting the collected data, such as the custom metrics.

9. To view the data sent to the AWS CloudWatch, go to the AWS CloudWatch console and “View Metrics”.

10. Select “System/Windows:InstanceID”.

11. It displays all the metrics available for the selected viewing. Metrics for the memory available, memory utilization, page available, page utilized and page used in step#7 have been sent.

12. Select any metric to view its history graph.

13. Run the mon-put-metrics-perfmon script to get the PerfMon metrics.

14. Run the following command:

mon-put-metrics-perfmon.ps1 -aws_credential_file C:\AWS\AmazonCloudWatchMonitoringWindows\awscreds.conf -pages_input -processor_queue –verbose

15. To view the Perfmon metrics of the instance in CloudWatch, go to the CloudWatch dashboard and click on “View Metrics”.

16. Select “System/Windows:InstanceID, Perfmon Counter” from the viewing.

17. Select the metric, which will list the data.

18. Run the mon-put-metrics-disk script to get the disk data metrics.

19. Run the following command:

.\mon-put-metrics-disk.ps1 -aws_credential_file C:\AWS\AmazonCloudWatchMonitoringWindows\awscreds.conf -disk_drive C: -disk_space_util -disk_space_used -disk_space_avail -disk_space_units Gigabytes –verbose

20. Go to the AWS CloudWatch dashboard and select Metrics. Select “System/Windows:Drive-Letter,InstanceID” from the viewing.

21. It lists the metrics from the data sent in step#19.

22. In order to collect data from the windows instance periodically, you can setup a batch process which will execute at a predefined frequency and send data to the AWS CloudWatch.


[Newvem analytics tracks you AWS cloud utilization:

  • Hourly Utilization Pattern Analysis 
  • Reserved Instances Decision Tool 
  • Resource Resizing Opportunities

Get Started for Free or Learn More]


Keywords: Amazon web services, Amazon AWS console, Amazon AWS instances, EC2 Service, Amazon cloud computing, Amazon EC2 capacity, Cloud Monitoring, AWS CloudWatch, Cloud Utilization, CloudWatch Alarm, EC2 Instance, AWS SDK, CloudWatch Powershell, CLI tools, Amazon Cloud API

You must be to post a comment.

* As a bonus, you'll receive our weekly newsletter!

Hitchhiker's Guide to The Cloud

Newvem's eBook for Cloud Operations