Data points are empty when using AWS cli on powershell

I am trying to get statistics for my ec2 instance using Powershell. I just get empty data points on startup. Any solutions?

The code is below:

Get-CWMetricStatistics -MetricName CPUUtilization 
                    -Dimension @{Name = "InstanceId"; Value = "08b290d4ab98f79c3"} 
                    -StartTime (Get-Date).AddDays(-1) 
                    -EndTime (Get-Date) 
                    -Namespace "AWS/EC2" 
                    -Period 60 
                    -Statistic Average

      


Output:

Datapoints Label         
---------- -----
{}         CPUUtilization

      

+3


source to share


1 answer


To answer the question:

Empty data output can be returned for many reasons, but generally means there is no data in CloudWatch for your data. Make sure your entries are correct and that there is data for the given time period.

I was able to reproduce empty data points in the following scenarios to give you some idea of ​​how this can lead to empty results:

  • Changed the letter on my InstanceId so that it does not match any of my copies; this is not an error, it just creates an empty dataset.
  • Changed the range of time before the instance was operational.
  • Use wrong permissions in powershell, so the profile I was using did not have permission to see the instance I was asking for.

For what it's worth, your syntax is valid. I tested your exact cmdlet with one of my own instances and it worked great. After you get your example working, you can get the raw data points by traversing the resulting collection and parsing them. For example, if the output of your cmdlet is in $datapoints

:

$datapoints | % { $_.Datapoints.Average }

To respond to a comment:

The syntax is -Dimension @{Name = "InstanceId"; Value = "08b290d4ab98f79c3"}

valid for this cmdlet. This looks so strange because the Get-CWMetricStatistics cmdlet expects you to navigate to the AWS.CloudWatch.Model.Dimension object collection .



For this example, a hash table with matching property names (Name and Value) is sufficient, but this example @{'InstanceId'='08b290d4ab98f79c3'}

will not be because AWS.CloudWatch.Model.Dimension is missing an "InstanceId" parameter.

In fact, the startup that returns this error:

Get-CWMetricStatistics: Cannot bind Size parameter. Can't create an object of type "Amazon.CloudWatch.Model.Dimension". InstanceId property not found for Amazon.CloudWatch.Model.Dimension object. Available property: [Name], [Value]

Consider also that passing in a set of hash tables is valid input for this cmdlet:

-Dimension @(@{Name = "InstanceId"; Value = "i-abcd1234"},@{Name = "InstanceId"; Value = "i-efgh5678"})

      

Further reading:

AWS PowerShell Documentation - Get-CWMetricStatistics

0


source







All Articles