Amazon CloudWatch监视Windows Server2008的磁盘空间使用率配置

作者:袖梨 2022-06-30

 

在AWS启动Windows Server2008之后,默认以安装了EC2ConfigService。

在这里介绍一下,使用EC2ConfigService服务创建CloudWatch自定义监视磁盘使用率。

EC2ConfigServiceSettings

修改EC2ConfigServiceSettings配置

修改JSON文件

重启EC2ConfigService

1. 修改EC2ConfigServiceSettings配置

启动C:Program FilesAmazonEc2ConfigServiceEc2ConfigServiceSettings.exe之后,勾选「Enable CloudWatch Logs integratin.」。

 

2. 修改JSON文件

接着修改C:Program FilesAmazonEc2ConfigServiceSettings文件夹下面的AWS.EC2.Windows.CloudWatch.json文件。

在这里仅监视Windows Server的磁盘使用率。

{
    "EngineConfiguration": {
        "PollInterval": "00:05:00",
        "Components": [
            {
                "Id": "PerformanceCounter",
                "FullName": "AWS.EC2.Windows.CloudWatch.PerformanceCounterComponent.PerformanceCounterInputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters": {
                    "CategoryName": "LogicalDisk",
                    "CounterName": "% Free Space",
                    "InstanceName": "C:",
                    "MetricName": "DiskFree",
                    "Unit": "Percent",
                    "DimensionName": "InstanceId",
                    "DimensionValue": "{instance_id}"
                }
            },
            {
                "Id": "CloudWatch",
                "FullName": "AWS.EC2.Windows.CloudWatch.CloudWatch.CloudWatchOutputComponent,AWS.EC2.Windows.CloudWatch",
                "Parameters":
                {
                    "AccessKey": "[填写AccessKey]",
                    "SecretKey": "[填写SecretKey]",
                    "Region": "[填写Region]",
                    "NameSpace": "Windows/Default"
                }
            }
        ],
        "Flows": {
            "Flows":
            [
                "PerformanceCounter,CloudWatch"
            ]
        }
    }
}
3. 重启EC2ConfigService

>net stop ec2config
The Ec2Config service is stopping..
The Ec2Config service was stopped successfully.

>net start ec2config
The Ec2Config service is starting.
The Ec2Config service was started successfully.
在CloudWatch,确认是否获取到监控值

点击「Metrics」下面的「Windows/Default」。

 

确认DiskFree的值。

 

结语

在这里没有提IAM用户及角色(至少给用户附加CloudWatchFullAccess策略),给EC2赋予权限的方法一般有2种。

启动EC2之前创建角色,并在启动EC2时把创建好的角色赋予到EC2
创建拥有指定策略的用户,并使用该用户的AccessKey和SecretKey访问AWS的各种资源。

相关文章

精彩推荐