AWS响应中的数据点为空

时间:2014-10-27 15:51:31

标签: .net amazon-web-services aws-sdk

我有一个获取实例统计信息的函数。它通过严格的细节。但不幸的是,我只是获得空数据点。有任何想法吗?

public Object getMetricStatisticResults(Credentials creds, Amazon.RegionEndpoint region, string instanceID, int period, string[] statistics, DateTime starttime, DateTime endtime )
        {
            var client = AWSClientFactory.CreateAmazonCloudWatchClient(creds, region);
            var dimension = new Dimension
            {
                Name = "InstanceID",
                Value = instanceID
            };

            var request = new GetMetricStatisticsRequest();
            request.Dimensions.Add(dimension);


            var currentTime = DateTime.UtcNow;

            request.StartTime = starttime; //checked and it is all correct! -5 days
            request.EndTime = endtime; //checked, showing now value!

            request.Namespace = "AWS/EC2"; //not sure what this is but added in as per examples

            request.MetricName = "CPUUtilization"; //what I want to get
            request.Statistics.Add("Average"); //I want others but reducing to minimum so that I can test the easier part.
            request.Period = 300;
            var response = client.GetMetricStatistics(request);

            if(response.Datapoints.Count > 0)
            {
               //never happens
            }
            else
            {
               //always happens!!! grrrrr
            }
        }

我也尝试过改变区域区域(我做了一些谷歌搜索),但这并没有解决我的问题,我可以确认选择的那个是正确的。

主AWS控制台中是否需要启用此功能?我错过了什么吗?到目前为止花了很长时间测试不同的东西,但没有真正起作用。非常感谢您的帮助。

谢谢!

1 个答案:

答案 0 :(得分:0)

问题在于以下代码行:

{
                Name = "InstanceID",
                Value = instanceID
            };

它应该说“InstanceId”,注意最后的小'd'。这解决了我。 解决方案:

  {
                    Name = "InstanceId",
                    Value = instanceID
                };