Search code examples
amazon-web-servicesamazon-cloudwatchwindows-server

CloudWatch Agent Windows LogicalDisk metric - selecting a volume


I want to send a custom metric for the free space on the C: volume on my Windows Server 2019 EC2 instances. So, I installed, configured, and started the CloudWatch agent. When I check on CloudWatch, I see it in the metrics, but there are a bunch of other volume instances which look like HarddiskVolume####:

enter image description here

Maybe since this is a ECS instance these are related to the Docker containers running on them, but I only care about the free space of the C: volume. Is there a way to filter only a certain volume in the CloudWatch agent? I don't want to have to pay for all these metrics I'm not using. I tried adding a custom dimension with instance as the key and C: as the value but it didn't do anything.

Looking online I see there is such a filter when sending metrics from the SSMAgent but from what I understand the CW agent is a replacement for that.

Here is my CW agent configuration file:

{
    "agent": {
        "metrics_collection_interval": 60,
        "logfile": "c:\\ProgramData\\Amazon\\AmazonCloudWatchAgent\\Logs\\amazon-cloudwatch-agent.log"
    },
    "metrics": {
        "append_dimensions": {
            "AutoScalingGroupName":"${aws:AutoScalingGroupName}",
            "ImageID":"${aws:ImageId}",
            "InstanceId":"${aws:InstanceId}",
            "InstanceType":"${aws:InstanceType}"
        },
        "metrics_collected": {
            "LogicalDisk": {
                "measurement": [
                    "% Free Space"
                ],
                "resources": [
                    "*"
                ]
            },
            "Memory": {
                "measurement": [
                    "% Committed Bytes In Use"
                ]
            }
        }
    }
}

Solution

  • Your CloudWatch Agent is collecting the % Free Space for all discovered disks because you've specified * in the resources array. You can tell the Agent to gather the measurement only from the C: drive like the below. Be sure to restart the Windows Service after you've made and saved each config change.

    {
        ...
        "metrics": {
            "metrics_collected": {
                "LogicalDisk": {
                    "measurement": [
                        { "name": "% Free Space", "unit": "Percent" }
                    ],
                    "resources": [
                        "C:"
                    ]
                },
                ...
            }
        }
    }