Why isn't my CloudWatch GetMetricStatistics API call returning data points? 

Last updated: 2018-06-05

My Amazon CloudWatch "GetMetricStatistics" API call isn't returning any data points. However, the data points are available on the CloudWatch console. How can I resolve this?

Resolution

Note: If you receive errors when running AWS Command Line Interface (AWS CLI) commands, make sure that you’re using the most recent AWS CLI version.

CloudWatch is a regional service, so it's important to be sure that the API call uses the correct Region. The GetMetricStatistics API call is issued with multiple arguments, and they must match the properties of the metric. These arguments are case-sensitive, so you must be sure that the names and cases match in the CloudWatch console configuration. Most often, errors are caused by incorrect arguments.

Dimensions

If the metric was created with multiple dimensions, the data points for that metric can be retrieved only by specifying all the configured dimensions. For example, if you publish a metric named ServerStats in the DataCenterMetric namespace with these properties:

Dimensions: Server=Prod, Domain=Frankfurt, Unit: Count, Timestamp: 2016-10-31T12:30:00Z, Value: 105

You can retrieve data points for this metric by specifying these dimensions:

Server=Prod,Domain=Frankfurt

However, you can't retrieve the data points if you specify just one of the two dimensions. For example:

Server=Prod

With the AWS CLI, the format for specifying dimensions in the get-metric-statistics command is different from the put-metric-data command. Be sure to use a format similar to the following:

"Name"=string, "Value"=string

instead of this format:

Name=Value

Example of the get-metric-statistics call:

aws cloudwatch get-metric-statistics --metric-name "MyMetric" --start-time 2018-04-08T23:18:00Z --end-time 2018-04-09T23:18:00Z --period 3600 --namespace "MyNamespace" --statistics Maximum --dimensions Name=Server,Value=Prod

Example of the put-metric-data call:

aws cloudwatch put-metric-data --namespace "MyNamespace" --metric-name "MyMetric" --dimensions Server=Prod --value 10

Period

If the metric isn't pushed for the specified period value, no data points are returned.

For example, if you enabled basic monitoring for an instance, Amazon EC2 pushes data points every five minutes. Let's say that Amazon EC2 pushes the data points at time stamps 12:00, 12:05, 12:10, and so on. If you have your start time and end time within 12:01 and 12:04, and then try to retrieve the data points with a period of 60 seconds, you won't see any data points. It's a best practice to have your start time and end time extend beyond the minimum granularity offered by the metric (5 minutes in this case). Or, use a period that is greater than or equal to the minimum granularity offered by the metric.

Statistics

To retrieve percentile statistics for a metric, use ExtendedStatistic.

CloudWatch uses raw data points to calculate percentiles. If you publish data using a statistic set, you can retrieve percentile statistics for this data only if one of the following conditions are true:

  • The SampleCount of the statistic set is 1.
  • The Min and the Max of the statistic set are equal.

Unit

  • If the specified unit is different from the one that's configured for the metric, no data points are returned.
  • If you don't specify the unit argument, data points for all units are returned.

Start time and end time

  • Format the start time and the end time arguments as specified in the GetMetricStatistics documentation.
  • If no data points are pushed for the metric between the start time and end time, then no data points are returned.

Note: Data points with time stamps from 24 hours ago or longer can take at least 48 hours to become available for get-metric-statistics. For more information, see put-metric-data.


Did this article help?


Do you need billing or technical support?