0

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

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 控制台中是否需要启用某些东西才能实现这一点?我错过了什么吗?到目前为止花了很长时间测试不同的东西,但没有任何效果。非常感谢您的帮助。

谢谢!

4

1 回答 1

0

问题在于以下代码行:

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

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

  {
                    Name = "InstanceId",
                    Value = instanceID
                };
于 2014-10-27T16:39:20.733 回答