c# – AWS – 如何在AWSSDK for .NET中更改cloudwatchclient配置服务版本

前端之家收集整理的这篇文章主要介绍了c# – AWS – 如何在AWSSDK for .NET中更改cloudwatchclient配置服务版本前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用CloudWatch获取特定亚马逊EC2实例的cpu百分比

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

The requested version (2010-08-01) of service AmazonEC2 does not exist”

我无法在AmazonCloudWatchClient中更改ServiceVersion,因为它具有只读属性

默认设置为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 + "%");
            }
        }

解决方法

为什么你认为你需要改变日期?

属性确实没有setter(参见code),因此您将无法使用此类属性定义配置.

我知道你不想透露你的信息,但你有什么信息

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

名称应该是InstanceName,如果您使用实例ID,则在Value中指示它应该是InstanceId

var dimension = new Dimension
        {
            Name = "InstanceId"
            Value = "i-54cfb999"
        };

猜你在找的C#相关文章