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

4 minute read
0

My Amazon CloudWatch "GetMetricStatistics" API call isn't returning any data points. However, the data points are available on the CloudWatch console.

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 make sure that the API call uses the correct AWS Region. CloudWatch issues the GetMetricStatistics API call with multiple arguments, and those arguments must match the properties of the metric. These arguments are case sensitive, so be sure that the names and cases match in the CloudWatch console configuration. Errors are most often the result of incorrect arguments.

Dimensions

If the metric is created with multiple dimensions, then you can retrieve the data points for that only if you specify all the configured dimensions. For example, suppose 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

To retrieve data points for this metric, specify the following dimensions:

Server=Prod,Domain=Frankfurt

However, if you specify just one of the two dimensions, then you can't retrieve the data points. See the following 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

Note: In this case, a format of Name=Value is unsuccessful.

See the following example of a 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

See the following example of a 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, then no data points are returned.

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

Statistics

To retrieve percentile statistics for a metric, use ExtendedStatistic.

CloudWatch uses raw data points to calculate percentiles. When you publish data using a statistic set, you can retrieve percentile statistics for this data only if one of the following conditions is 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, then no data points are returned.
  • If you don't specify the unit argument, then 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 timestamps 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.


Related information

AWS services that publish CloudWatch metrics

AWS OFFICIAL
AWS OFFICIALUpdated a year ago
1 Comment

This needs to be in the OFFICIAL AWS DOCUMENTATION FOR CLOUDWATCH GET-METRIC-STATISTICS! Whoever wrote this is a genius and I will sell them my first-born child as this just solved hours of guessing and testing all to find out that the dimension names are CASE SENSITIVE and ClientID is not going to work when it expects ClientId.

replied a month ago