我正在尝试使用CloudWatch获取特定亚马逊EC2实例的CPU百分比
我在执行代码时遇到此错误(见下文)
服务AmazonEC2的请求版本(2010-08-01)不存在“
我无法更改AmazonCloudWatchClient中的ServiceVersion,因为它有Read Only property
默认设置为2010-08-01
我需要将ServiceVersion更改为2014-10-01
请查看以下配置
此处配置文字
var client = new AmazonCloudWatchClient(clientkey,secretkey,new AmazonCloudWatchConfig{ServiceURL="url"})
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
var request = new GetMetricStatisticsRequest
{
Dimensions = new List<Dimension>() { dimension },
EndTime = DateTime.Today,
MetricName = "CPUUtilization",
Namespace = "AWS/EC2",
// Get statistics by day.
Period = (int)TimeSpan.FromDays(1).TotalSeconds,
// Get statistics for the past month.
StartTime = DateTime.Today.Subtract(TimeSpan.FromDays(30)),
Statistics = new List<string>() { "Minimum" },
Unit = StandardUnit.Percent
};
var response = client.GetMetricStatistics(request);
if (response.Datapoints.Count > 0)
{
foreach (var point in response.Datapoints)
{
Console.WriteLine(point.Timestamp.ToShortDateString() +
" " + point.Minimum + "%");
}
}
答案 0 :(得分:0)
为什么你认为你需要改变日期?
该属性确实没有setter(请参阅code),因此您将无法使用此类属性定义配置。
我知道你不想透露你的信息,但你有什么
var dimension = new Dimension
{
Name = "instanceName",
Value = "instanceID"
};
名称应为InstanceName
,如果您使用实例ID,则在值中指示它应该是InstanceId
类似
var dimension = new Dimension
{
Name = "InstanceId"
Value = "i-54cfb999"
};