How do I use the CloudWatch agent on a Windows Server to view metrics for Performance Monitor?

4 minute read
0

I want to use the Amazon CloudWatch agent on a Windows Server to get the metrics that are collected for Performance Monitor.

Resolution

To install and configure the CloudWatch agent on your Windows Server and view the metrics for Windows Performance Monitor, complete the following steps.

Prerequisites:

  • An Amazon Elastic Compute Cloud (Amazon EC2) instance on a public subnet with access to the internet. Or, an EC2 instance on a private subnet with access to Amazon Virtual Private Cloud (Amazon VPC) endpoints.
  • An AWS Identity and Access Management (IAM) profile and role for the instance.
  • AWS Systems Manager Agent (SSM Agent).
  • The CloudWatch agent.

Start your instance

Complete the following steps:

  1. Start your instance.
  2. Use a remote desktop protocol (RDP) to connect to your instance.
    Note: The CloudWatch agent supports Windows Servers 2016, 2019, and 64-bit versions of Windows Server 2022

Install the CloudWatch agent

To install the CloudWatch agent, either automatically or manually download the agent.

Automatically download the CloudWatch agent

To use the AWS-ConfigureAWS package to install the agent, see Installing the CloudWatch agent on EC2 instances using your agent configuration.

Manually download the CloudWatch agent

To manually download the CloudWatch agent, run the following command:

Invoke-WebRequest -Uri  
 https://s3.amazonaws.com/amazoncloudwatch-agent/windows/amd64/latest/amazon-cloudwatch-agent.msi  
 -OutFile $env:USERPROFILE\Downloads\amazon-cloudwatch-agent.msi   
-UseBasicParsing  
Invoke-Item $env:USERPROFILE\Downloads\amazon-cloudwatch-agent.msi

Create the configuration file

After you download the .msi file, use the wizard to create the JSON configuration file. Or, you can manually create the configuration file.

Use the wizard to create the CloudWatch agent configuration file

  1. Use amazon-cloudwatch-agent-config-wizard to create the CloudWatch agent configuration file.
    Example file:

    {  
       "logs": {
        "logs_collected": {
          "files": {
            "collect_list": [
              {
                "file_path": "C:\\Users\\Administrator\\Desktop\\CWMetricsLogs",
                "log_group_name": "CWMetricsLogs",
                "log_stream_name": "{instance_id}",
                "retention_in_days": -1
              }
            ]
          },
          "windows_events": {
            "collect_list": [
              {
                "event_format": "xml",
                "event_levels": [
                  "VERBOSE",
                  "INFORMATION",
                  "WARNING",
                  "ERROR",
                  "CRITICAL"
                ],
                "event_name": "CloudWatchAgent",
                "log_group_name": "CloudWatchAgent",
                "log_stream_name": "{instance_id}",
                "retention_in_days": -1
              }
            ]
          }
        }
      },
      "metrics": {
        "aggregation_dimensions": [
          [
            "InstanceId"
          ]
        ],
        "append_dimensions": {
          "AutoScalingGroupName": "${aws:AutoScalingGroupName}",
          "ImageId": "${aws:ImageId}",
          "InstanceId": "${aws:InstanceId}",
          "InstanceType": "${aws:InstanceType}"
        },
        "metrics_collected": {
          "LogicalDisk": {
            "measurement": [
              "% Free Space"
            ],
            "metrics_collection_interval": 30,
            "resources": [
              "*"
            ]
          },
          "Memory": {
            "measurement": [
              "% Committed Bytes In Use"
            ],
            "metrics_collection_interval": 30
          },
          "Paging File": {
            "measurement": [
              "% Usage"
            ],
            "metrics_collection_interval": 30,
            "resources": [
              "*"
            ]
          },
          "PhysicalDisk": {
            "measurement": [
              "% Disk Time",
              "Disk Write Bytes/sec",
              "Disk Read Bytes/sec",
              "Disk Writes/sec",
              "Disk Reads/sec"
            ],
            "metrics_collection_interval": 30,
            "resources": [
              "*"
            ]
          },
          "Processor": {
            "measurement": [
              "% User Time",
              "% Idle Time",
              "% Interr\upt Time"
            ],
            "metrics_collection_interval": 30,
            "resources": [
              "*"
            ]
          },
          "TCPv4": {
            "measurement": [
              "Connections Established"
            ],
            "metrics_collection_interval": 30
          },
          "TCPv6": {
            "measurement": [
              "Connections Established"
            ],
            "metrics_collection_interval": 30
          },
          "statsd": {
            "metrics_aggregation_interval": 60,
            "metrics_collection_interval": 30,
            "service_address": ":8125"
          }
        }
      }
    }
  2. (Optional) to add other performance counters that are available in Performance Monitor, you run the following command:

    "PerformanceCounter-Family(processor, logical disk, memory etc.)": {  
      "measurement": [
          "Counter-name ("%Usage, "% free space" etc.)"
        ],
      "metrics_collection_interval": 30,
      "resources": [
        "Counter Property ( "_total", "C:/" etc.)
      ]
    },

    Note: In the preceding command, replace the example values with your values. Also, make sure that the counters are visible in Windows Performance Monitor so that the agent can push datapoints for the counter.

  3. Find the file in C:\Program Files\Amazon\AmazonCloudWatchAgent.

  4. To start the CloudWatch agent, run the following Windows PowerShell command:

    "C:\Program Files\Amazon\AmazonCloudWatchAgent\amazon-cloudwatch-agent-ctl.ps1" -a fetch-config -m ec2 -s -c file:"C:\Program Files\Amazon\AmazonCloudWatchAgent\config.json"

Manually create the configuration file

For information about how to manually create the JSON file, see Manually create or edit the CloudWatch agent configuration file.

Example schema definition for the configuration file for Windows Servers:

installation-directory/amazon-cloudwatch-agent-schema.json

After you create the file, copy the file to the other Windows Servers where you want to install the agent in.

View the Performance Counters metrics in CloudWatch

Complete the following steps:

  1. Open the CloudWatch console.
  2. In the navigation pane, under Metrics, choose All Metrics.
  3. In the Custom namespaces section, choose CWAgent.
  4. Sort by ImageID, InstanceID, InstanceType, instance, objectname, or InstanceID.

Related information

Collect metrics, logs, and traces with the CloudWatch agent

AWS OFFICIAL
AWS OFFICIALUpdated 3 months ago