AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.
The maximum number of data points that can be queried is 50,850, whereas the maximum
number of data points returned from a single GetMetricStatistics
request
is 1,440. If you make a request that generates more than 1,440 data points, Amazon
CloudWatch returns an error. In such a case, you can alter the request by narrowing
the specified time range or increasing the specified period. Alternatively, you can
make multiple requests across adjacent time ranges. GetMetricStatistics
does not return the data in chronological order.
Amazon CloudWatch aggregates data points based on the length of the period
that you specify. For example, if you request statistics with a one-minute granularity,
Amazon CloudWatch aggregates data points with time stamps that fall within the same
one-minute period. In such a case, the data points queried can greatly outnumber the
data points returned.
The following examples show various statistics allowed by the data point query maximum
of 50,850 when you call GetMetricStatistics
on Amazon EC2 instances with
detailed (one-minute) monitoring enabled:
For information about the namespace, metric names, and dimensions that other Amazon Web Services products use to send metrics to CloudWatch, go to Amazon CloudWatch Metrics, Namespaces, and Dimensions Reference in the Amazon CloudWatch Developer Guide.
Namespace: Amazon.CloudWatch
Assembly: AWSSDK.dll
Version: (assembly version)
public virtual GetMetricStatisticsResponse GetMetricStatistics( GetMetricStatisticsRequest request )
Container for the necessary parameters to execute the GetMetricStatistics service method.
Exception | Condition |
---|---|
InternalServiceException | Indicates that the request processing has failed due to some unknown error, exception, or failure. |
InvalidParameterCombinationException | Parameters that must not be used together were used together. |
InvalidParameterValueException | Bad or out-of-range value was supplied for the input parameter. |
MissingRequiredParameterException | An input parameter that is mandatory for processing the request is not supplied. |
This example shows how to get statistics for a metric.
var client = new AmazonCloudWatchClient(); var dimension = new Dimension { Name = "InstanceType", Value = "t1.micro" }; var request = new GetMetricStatisticsRequest { Dimensions = new List<Dimension>() { dimension }, EndTime = DateTime.Today, MetricName = "CPUUtilization", Namespace = "AWS/EC2", // Get statistics by day. Period = (int)TimeSpan.FromDays(1).TotalSeconds, // Get statistics for the past month. StartTime = DateTime.Today.Subtract(TimeSpan.FromDays(30)), Statistics = new List<string>() { "Minimum" }, Unit = StandardUnit.Percent }; var response = client.GetMetricStatistics(request); if (response.Datapoints.Count > 0) { foreach (var point in response.Datapoints) { Console.WriteLine(point.Timestamp.ToShortDateString() + " " + point.Minimum + "%"); } }
.NET Framework:
Supported in: 4.5, 4.0, 3.5