1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package cloudwatch 4 5import ( 6 "context" 7 awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware" 8 "github.com/aws/aws-sdk-go-v2/aws/signer/v4" 9 "github.com/aws/aws-sdk-go-v2/service/cloudwatch/types" 10 "github.com/aws/smithy-go/middleware" 11 smithyhttp "github.com/aws/smithy-go/transport/http" 12 "time" 13) 14 15// Gets statistics for the specified metric. The maximum number of data points 16// returned from a single call is 1,440. If 17// 18// you request more than 1,440 data 19// points, CloudWatch returns an error. To reduce the number of data points, you 20// can narrow the specified time range and make multiple requests across adjacent 21// time ranges, or you can increase the specified period. Data points are not 22// returned in chronological order. CloudWatch aggregates data points based on the 23// length of the period that you specify. For example, if you request statistics 24// with a one-hour period, CloudWatch aggregates all data points with time stamps 25// that fall within each one-hour period. Therefore, the number of values 26// aggregated by CloudWatch is larger than the number of data points returned. 27// CloudWatch needs raw data points to calculate percentile statistics. If you 28// publish data using a statistic set instead, you can only retrieve percentile 29// statistics for this data if one of the following conditions is true: 30// 31// * The 32// SampleCount value of the statistic set is 1. 33// 34// * The Min and the Max values of 35// the statistic set are equal. 36// 37// Percentile statistics are not available for 38// metrics when any of the metric values are negative numbers. Amazon CloudWatch 39// retains metric data as follows: 40// 41// * Data points with a period of less than 60 42// seconds are available for 3 hours. These data points are high-resolution metrics 43// and are available only for custom metrics that have been defined with a 44// StorageResolution of 1. 45// 46// * Data points with a period of 60 seconds (1-minute) 47// are available for 15 days. 48// 49// * Data points with a period of 300 seconds 50// (5-minute) are available for 63 days. 51// 52// * Data points with a period of 3600 53// seconds (1 hour) are available for 455 days (15 months). 54// 55// Data points that are 56// initially published with a shorter period are aggregated together for long-term 57// storage. For example, if you collect data using a period of 1 minute, the data 58// remains available for 15 days with 1-minute resolution. After 15 days, this data 59// is still available, but is aggregated and retrievable only with a resolution of 60// 5 minutes. After 63 days, the data is further aggregated and is available with a 61// resolution of 1 hour. CloudWatch started retaining 5-minute and 1-hour metric 62// data as of July 9, 2016. For information about metrics and dimensions supported 63// by AWS services, see the Amazon CloudWatch Metrics and Dimensions Reference 64// (https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CW_Support_For_AWS.html) 65// in the Amazon CloudWatch User Guide. 66func (c *Client) GetMetricStatistics(ctx context.Context, params *GetMetricStatisticsInput, optFns ...func(*Options)) (*GetMetricStatisticsOutput, error) { 67 if params == nil { 68 params = &GetMetricStatisticsInput{} 69 } 70 71 result, metadata, err := c.invokeOperation(ctx, "GetMetricStatistics", params, optFns, addOperationGetMetricStatisticsMiddlewares) 72 if err != nil { 73 return nil, err 74 } 75 76 out := result.(*GetMetricStatisticsOutput) 77 out.ResultMetadata = metadata 78 return out, nil 79} 80 81type GetMetricStatisticsInput struct { 82 83 // The time stamp that determines the last data point to return. The value 84 // specified is exclusive; results include data points up to the specified time 85 // stamp. In a raw HTTP query, the time stamp must be in ISO 8601 UTC format (for 86 // example, 2016-10-10T23:00:00Z). 87 // 88 // This member is required. 89 EndTime *time.Time 90 91 // The name of the metric, with or without spaces. 92 // 93 // This member is required. 94 MetricName *string 95 96 // The namespace of the metric, with or without spaces. 97 // 98 // This member is required. 99 Namespace *string 100 101 // The granularity, in seconds, of the returned data points. For metrics with 102 // regular resolution, a period can be as short as one minute (60 seconds) and must 103 // be a multiple of 60. For high-resolution metrics that are collected at intervals 104 // of less than one minute, the period can be 1, 5, 10, 30, 60, or any multiple of 105 // 60. High-resolution metrics are those metrics stored by a PutMetricData call 106 // that includes a StorageResolution of 1 second. If the StartTime parameter 107 // specifies a time stamp that is greater than 3 hours ago, you must specify the 108 // period as follows or no data points in that time range is returned: 109 // 110 // * Start 111 // time between 3 hours and 15 days ago - Use a multiple of 60 seconds (1 112 // minute). 113 // 114 // * Start time between 15 and 63 days ago - Use a multiple of 300 115 // seconds (5 minutes). 116 // 117 // * Start time greater than 63 days ago - Use a multiple of 118 // 3600 seconds (1 hour). 119 // 120 // This member is required. 121 Period *int32 122 123 // The time stamp that determines the first data point to return. Start times are 124 // evaluated relative to the time that CloudWatch receives the request. The value 125 // specified is inclusive; results include data points with the specified time 126 // stamp. In a raw HTTP query, the time stamp must be in ISO 8601 UTC format (for 127 // example, 2016-10-03T23:00:00Z). CloudWatch rounds the specified time stamp as 128 // follows: 129 // 130 // * Start time less than 15 days ago - Round down to the nearest whole 131 // minute. For example, 12:32:34 is rounded down to 12:32:00. 132 // 133 // * Start time between 134 // 15 and 63 days ago - Round down to the nearest 5-minute clock interval. For 135 // example, 12:32:34 is rounded down to 12:30:00. 136 // 137 // * Start time greater than 63 138 // days ago - Round down to the nearest 1-hour clock interval. For example, 139 // 12:32:34 is rounded down to 12:00:00. 140 // 141 // If you set Period to 5, 10, or 30, the 142 // start time of your request is rounded down to the nearest time that corresponds 143 // to even 5-, 10-, or 30-second divisions of a minute. For example, if you make a 144 // query at (HH:mm:ss) 01:05:23 for the previous 10-second period, the start time 145 // of your request is rounded down and you receive data from 01:05:10 to 01:05:20. 146 // If you make a query at 15:07:17 for the previous 5 minutes of data, using a 147 // period of 5 seconds, you receive data timestamped between 15:02:15 and 15:07:15. 148 // 149 // This member is required. 150 StartTime *time.Time 151 152 // The dimensions. If the metric contains multiple dimensions, you must include a 153 // value for each dimension. CloudWatch treats each unique combination of 154 // dimensions as a separate metric. If a specific combination of dimensions was not 155 // published, you can't retrieve statistics for it. You must specify the same 156 // dimensions that were used when the metrics were created. For an example, see 157 // Dimension Combinations 158 // (https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#dimension-combinations) 159 // in the Amazon CloudWatch User Guide. For more information about specifying 160 // dimensions, see Publishing Metrics 161 // (https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html) 162 // in the Amazon CloudWatch User Guide. 163 Dimensions []types.Dimension 164 165 // The percentile statistics. Specify values between p0.0 and p100. When calling 166 // GetMetricStatistics, you must specify either Statistics or ExtendedStatistics, 167 // but not both. Percentile statistics are not available for metrics when any of 168 // the metric values are negative numbers. 169 ExtendedStatistics []string 170 171 // The metric statistics, other than percentile. For percentile statistics, use 172 // ExtendedStatistics. When calling GetMetricStatistics, you must specify either 173 // Statistics or ExtendedStatistics, but not both. 174 Statistics []types.Statistic 175 176 // The unit for a given metric. If you omit Unit, all data that was collected with 177 // any unit is returned, along with the corresponding units that were specified 178 // when the data was reported to CloudWatch. If you specify a unit, the operation 179 // returns only data that was collected with that unit specified. If you specify a 180 // unit that does not match the data collected, the results of the operation are 181 // null. CloudWatch does not perform unit conversions. 182 Unit types.StandardUnit 183} 184 185type GetMetricStatisticsOutput struct { 186 187 // The data points for the specified metric. 188 Datapoints []types.Datapoint 189 190 // A label for the specified metric. 191 Label *string 192 193 // Metadata pertaining to the operation's result. 194 ResultMetadata middleware.Metadata 195} 196 197func addOperationGetMetricStatisticsMiddlewares(stack *middleware.Stack, options Options) (err error) { 198 err = stack.Serialize.Add(&awsAwsquery_serializeOpGetMetricStatistics{}, middleware.After) 199 if err != nil { 200 return err 201 } 202 err = stack.Deserialize.Add(&awsAwsquery_deserializeOpGetMetricStatistics{}, middleware.After) 203 if err != nil { 204 return err 205 } 206 if err = addSetLoggerMiddleware(stack, options); err != nil { 207 return err 208 } 209 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 210 return err 211 } 212 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 213 return err 214 } 215 if err = addResolveEndpointMiddleware(stack, options); err != nil { 216 return err 217 } 218 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 219 return err 220 } 221 if err = addRetryMiddlewares(stack, options); err != nil { 222 return err 223 } 224 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 225 return err 226 } 227 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 228 return err 229 } 230 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 231 return err 232 } 233 if err = addClientUserAgent(stack); err != nil { 234 return err 235 } 236 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 237 return err 238 } 239 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 240 return err 241 } 242 if err = addOpGetMetricStatisticsValidationMiddleware(stack); err != nil { 243 return err 244 } 245 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetMetricStatistics(options.Region), middleware.Before); err != nil { 246 return err 247 } 248 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 249 return err 250 } 251 if err = addResponseErrorMiddleware(stack); err != nil { 252 return err 253 } 254 if err = addRequestResponseLogging(stack, options); err != nil { 255 return err 256 } 257 return nil 258} 259 260func newServiceMetadataMiddleware_opGetMetricStatistics(region string) *awsmiddleware.RegisterServiceMetadata { 261 return &awsmiddleware.RegisterServiceMetadata{ 262 Region: region, 263 ServiceID: ServiceID, 264 SigningName: "monitoring", 265 OperationName: "GetMetricStatistics", 266 } 267} 268