AWS SDK Version 2 for .NET
API Reference

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.

.NET Framework 3.5
 
Container for the parameters to the GetMetricStatistics operation. Gets statistics for the specified metric.

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.

Inheritance Hierarchy

System.Object
  Amazon.Runtime.AmazonWebServiceRequest
    Amazon.CloudWatch.AmazonCloudWatchRequest
      Amazon.CloudWatch.Model.GetMetricStatisticsRequest

Namespace: Amazon.CloudWatch.Model
Assembly: AWSSDK.dll
Version: (assembly version)

Syntax

C#
public class GetMetricStatisticsRequest : AmazonCloudWatchRequest
         IRequestEvents

The GetMetricStatisticsRequest type exposes the following members

Constructors

Properties

NameTypeDescription
Public Property Dimensions System.Collections.Generic.List<Amazon.CloudWatch.Model.Dimension> Gets and sets the property Dimensions.

A list of dimensions describing qualities of the metric.

Public Property EndTime System.DateTime Gets and sets the property EndTime.

The time stamp to use for determining the last datapoint to return. The value specified is exclusive; results will include datapoints up to the time stamp specified. The time stamp must be in ISO 8601 UTC format (e.g., 2014-09-03T23:00:00Z).

Public Property MetricName System.String Gets and sets the property MetricName.

The name of the metric, with or without spaces.

Public Property Namespace System.String Gets and sets the property Namespace.

The namespace of the metric, with or without spaces.

Public Property Period System.Int32 Gets and sets the property Period.

The granularity, in seconds, of the returned datapoints. Period must be at least 60 seconds and must be a multiple of 60. The default value is 60.

Public Property StartTime System.DateTime Gets and sets the property StartTime.

The time stamp to use for determining the first datapoint to return. The value specified is inclusive; results include datapoints with the time stamp specified. The time stamp must be in ISO 8601 UTC format (e.g., 2014-09-03T23:00:00Z).

The specified start time is rounded down to the nearest value. Datapoints are returned for start times up to two weeks in the past. Specified start times that are more than two weeks in the past will not return datapoints for metrics that are older than two weeks.

Data that is timestamped 24 hours or more in the past may take in excess of 48 hours to become available from submission time using GetMetricStatistics.

Public Property Statistics System.Collections.Generic.List<System.String> Gets and sets the property Statistics.

The metric statistics to return. For information about specific statistics returned by GetMetricStatistics, see Statistics in the Amazon CloudWatch Developer Guide.

Public Property Unit Amazon.CloudWatch.StandardUnit Gets and sets the property Unit.

The unit for the metric.

Examples

This example shows how to get statistics for a metric.

Get metric statistics example

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 + "%");
  }
}
      

Version Information

.NET Framework:
Supported in: 4.5, 4.0, 3.5

.NET for Windows Store apps:
Supported in: Windows 8.1, Windows 8

.NET for Windows Phone:
Supported in: Windows Phone 8.1, Windows Phone 8