在AWS啟動Windows Server2008之後,預設以安裝了EC2ConfigService。
在這裡介紹一下,使用EC2ConfigService服務建立CloudWatch自訂監視磁碟使用率。
EC2ConfigServiceSettings
修改EC2ConfigServiceSettings配置
修改JSON檔案
重啟EC2ConfigService
1. 修改EC2ConfigServiceSettings配置
啟動C:\Program Files\Amazon\Ec2ConfigService\Ec2ConfigServiceSettings.exe之後,勾選「Enable CloudWatch Logs integratin.」。
2. 修改JSON檔案
接著修改C:\Program Files\Amazon\Ec2ConfigService\Settings檔案夾下面的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的各種資源。