2014-10-27 45 views
0

我有一個函數可以獲取實例的統計信息。它通過了嚴格的細節。但不幸的是,我只是獲得空的數據點。有任何想法嗎?AWS響應中的數據點爲空

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 
      } 
     } 

我試圖改變該區域的區域,以及(我做了一些google搜索),但並沒有解決我的問題,我可以確認選擇的是正確的反正。

AWS主控制檯中是否存在需要啓用的功能?我錯過了什麼嗎?花了很長時間測試不同的東西,但沒有真正起作用。非常感謝您的幫助。

謝謝!

回答

0

的問題是與下面的代碼行:

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

應該說「實例ID」,注意小「d」結尾。這爲我解決了它。 解決方案:

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