我正在尝试使用CloudWatch获得特定亚马逊EC2实例的CPU百分比

我在执行代码时遇到此错误(请参见下文)



我无法在AmazonCloudWatchClient中更改ServiceVersion,因为它具有Read Only property
默认设置为2010-08-01
我需要将ServiceVersion更改为2014-10-01
请在下面找到配置

c# - AWS-如何在适用于.NET的AWSSDK中更改cloudwatchclient配置服务版本-LMLPHP

以及此处的文本配置

  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 + "%");
            }
        }

最佳答案

为什么您认为需要更改日期?

该属性确实没有 setter (请参阅code),因此您将无法使用该属性定义配置。

我了解您不希望透露您的信息,但是您拥有什么

  var dimension = new Dimension
        {
            Name = "instanceName",
            Value = "instanceID"
        };

名称应为InstanceName,如果您使用Value中指示的实例ID,则名称应为InstanceId,例如
  var dimension = new Dimension
        {
            Name = "InstanceId"
            Value = "i-54cfb999"
        };

关于c# - AWS-如何在适用于.NET的AWSSDK中更改cloudwatchclient配置服务版本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37746103/

10-17 02:06