software.amazon.awssdk.services.cloudwatch.model.GetMetricStatisticsRequest Maven / Gradle / Ivy
Show all versions of cloudwatch Show documentation
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
* the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
package software.amazon.awssdk.services.cloudwatch.model;
import java.time.Instant;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.awscore.AwsRequestOverrideConfiguration;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*/
@Generated("software.amazon.awssdk:codegen")
public final class GetMetricStatisticsRequest extends CloudWatchRequest implements
ToCopyableBuilder {
private static final SdkField NAMESPACE_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("Namespace").getter(getter(GetMetricStatisticsRequest::namespace)).setter(setter(Builder::namespace))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Namespace").build()).build();
private static final SdkField METRIC_NAME_FIELD = SdkField. builder(MarshallingType.STRING)
.memberName("MetricName").getter(getter(GetMetricStatisticsRequest::metricName)).setter(setter(Builder::metricName))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("MetricName").build()).build();
private static final SdkField> DIMENSIONS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Dimensions")
.getter(getter(GetMetricStatisticsRequest::dimensions))
.setter(setter(Builder::dimensions))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Dimensions").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(Dimension::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField START_TIME_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("StartTime").getter(getter(GetMetricStatisticsRequest::startTime)).setter(setter(Builder::startTime))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("StartTime").build()).build();
private static final SdkField END_TIME_FIELD = SdkField. builder(MarshallingType.INSTANT)
.memberName("EndTime").getter(getter(GetMetricStatisticsRequest::endTime)).setter(setter(Builder::endTime))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("EndTime").build()).build();
private static final SdkField PERIOD_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("Period").getter(getter(GetMetricStatisticsRequest::period)).setter(setter(Builder::period))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Period").build()).build();
private static final SdkField> STATISTICS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Statistics")
.getter(getter(GetMetricStatisticsRequest::statisticsAsStrings))
.setter(setter(Builder::statisticsWithStrings))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Statistics").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> EXTENDED_STATISTICS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("ExtendedStatistics")
.getter(getter(GetMetricStatisticsRequest::extendedStatistics))
.setter(setter(Builder::extendedStatistics))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExtendedStatistics").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.STRING)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField UNIT_FIELD = SdkField. builder(MarshallingType.STRING).memberName("Unit")
.getter(getter(GetMetricStatisticsRequest::unitAsString)).setter(setter(Builder::unit))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Unit").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(NAMESPACE_FIELD,
METRIC_NAME_FIELD, DIMENSIONS_FIELD, START_TIME_FIELD, END_TIME_FIELD, PERIOD_FIELD, STATISTICS_FIELD,
EXTENDED_STATISTICS_FIELD, UNIT_FIELD));
private final String namespace;
private final String metricName;
private final List dimensions;
private final Instant startTime;
private final Instant endTime;
private final Integer period;
private final List statistics;
private final List extendedStatistics;
private final String unit;
private GetMetricStatisticsRequest(BuilderImpl builder) {
super(builder);
this.namespace = builder.namespace;
this.metricName = builder.metricName;
this.dimensions = builder.dimensions;
this.startTime = builder.startTime;
this.endTime = builder.endTime;
this.period = builder.period;
this.statistics = builder.statistics;
this.extendedStatistics = builder.extendedStatistics;
this.unit = builder.unit;
}
/**
*
* The namespace of the metric, with or without spaces.
*
*
* @return The namespace of the metric, with or without spaces.
*/
public final String namespace() {
return namespace;
}
/**
*
* The name of the metric, with or without spaces.
*
*
* @return The name of the metric, with or without spaces.
*/
public final String metricName() {
return metricName;
}
/**
* For responses, this returns true if the service returned a value for the Dimensions property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasDimensions() {
return dimensions != null && !(dimensions instanceof SdkAutoConstructList);
}
/**
*
* The dimensions. If the metric contains multiple dimensions, you must include a value for each dimension.
* CloudWatch treats each unique combination of dimensions as a separate metric. If a specific combination of
* dimensions was not published, you can't retrieve statistics for it. You must specify the same dimensions that
* were used when the metrics were created. For an example, see Dimension Combinations in the Amazon CloudWatch User Guide. For more information about specifying
* dimensions, see Publishing
* Metrics in the Amazon CloudWatch User Guide.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasDimensions} method.
*
*
* @return The dimensions. If the metric contains multiple dimensions, you must include a value for each dimension.
* CloudWatch treats each unique combination of dimensions as a separate metric. If a specific combination
* of dimensions was not published, you can't retrieve statistics for it. You must specify the same
* dimensions that were used when the metrics were created. For an example, see Dimension Combinations in the Amazon CloudWatch User Guide. For more information about
* specifying dimensions, see Publishing
* Metrics in the Amazon CloudWatch User Guide.
*/
public final List dimensions() {
return dimensions;
}
/**
*
* The time stamp that determines the first data point to return. Start times are evaluated relative to the time
* that CloudWatch receives the request.
*
*
* The value specified is inclusive; results include data points with the specified time stamp. In a raw HTTP query,
* the time stamp must be in ISO 8601 UTC format (for example, 2016-10-03T23:00:00Z).
*
*
* CloudWatch rounds the specified time stamp as follows:
*
*
* -
*
* Start time less than 15 days ago - Round down to the nearest whole minute. For example, 12:32:34 is rounded down
* to 12:32:00.
*
*
* -
*
* Start time between 15 and 63 days ago - Round down to the nearest 5-minute clock interval. For example, 12:32:34
* is rounded down to 12:30:00.
*
*
* -
*
* Start time greater than 63 days ago - Round down to the nearest 1-hour clock interval. For example, 12:32:34 is
* rounded down to 12:00:00.
*
*
*
*
* If you set Period
to 5, 10, or 30, the start time of your request is rounded down to the nearest
* time that corresponds to even 5-, 10-, or 30-second divisions of a minute. For example, if you make a query at
* (HH:mm:ss) 01:05:23 for the previous 10-second period, the start time of your request is rounded down and you
* receive data from 01:05:10 to 01:05:20. If you make a query at 15:07:17 for the previous 5 minutes of data, using
* a period of 5 seconds, you receive data timestamped between 15:02:15 and 15:07:15.
*
*
* @return The time stamp that determines the first data point to return. Start times are evaluated relative to the
* time that CloudWatch receives the request.
*
* The value specified is inclusive; results include data points with the specified time stamp. In a raw
* HTTP query, the time stamp must be in ISO 8601 UTC format (for example, 2016-10-03T23:00:00Z).
*
*
* CloudWatch rounds the specified time stamp as follows:
*
*
* -
*
* Start time less than 15 days ago - Round down to the nearest whole minute. For example, 12:32:34 is
* rounded down to 12:32:00.
*
*
* -
*
* Start time between 15 and 63 days ago - Round down to the nearest 5-minute clock interval. For example,
* 12:32:34 is rounded down to 12:30:00.
*
*
* -
*
* Start time greater than 63 days ago - Round down to the nearest 1-hour clock interval. For example,
* 12:32:34 is rounded down to 12:00:00.
*
*
*
*
* If you set Period
to 5, 10, or 30, the start time of your request is rounded down to the
* nearest time that corresponds to even 5-, 10-, or 30-second divisions of a minute. For example, if you
* make a query at (HH:mm:ss) 01:05:23 for the previous 10-second period, the start time of your request is
* rounded down and you receive data from 01:05:10 to 01:05:20. If you make a query at 15:07:17 for the
* previous 5 minutes of data, using a period of 5 seconds, you receive data timestamped between 15:02:15
* and 15:07:15.
*/
public final Instant startTime() {
return startTime;
}
/**
*
* The time stamp that determines the last data point to return.
*
*
* The value specified is exclusive; results include data points up to the specified time stamp. In a raw HTTP
* query, the time stamp must be in ISO 8601 UTC format (for example, 2016-10-10T23:00:00Z).
*
*
* @return The time stamp that determines the last data point to return.
*
* The value specified is exclusive; results include data points up to the specified time stamp. In a raw
* HTTP query, the time stamp must be in ISO 8601 UTC format (for example, 2016-10-10T23:00:00Z).
*/
public final Instant endTime() {
return endTime;
}
/**
*
* The granularity, in seconds, of the returned data points. For metrics with regular resolution, a period can be as
* short as one minute (60 seconds) and must be a multiple of 60. For high-resolution metrics that are collected at
* intervals of less than one minute, the period can be 1, 5, 10, 30, 60, or any multiple of 60. High-resolution
* metrics are those metrics stored by a PutMetricData
call that includes a
* StorageResolution
of 1 second.
*
*
* If the StartTime
parameter specifies a time stamp that is greater than 3 hours ago, you must specify
* the period as follows or no data points in that time range is returned:
*
*
* -
*
* Start time between 3 hours and 15 days ago - Use a multiple of 60 seconds (1 minute).
*
*
* -
*
* Start time between 15 and 63 days ago - Use a multiple of 300 seconds (5 minutes).
*
*
* -
*
* Start time greater than 63 days ago - Use a multiple of 3600 seconds (1 hour).
*
*
*
*
* @return The granularity, in seconds, of the returned data points. For metrics with regular resolution, a period
* can be as short as one minute (60 seconds) and must be a multiple of 60. For high-resolution metrics that
* are collected at intervals of less than one minute, the period can be 1, 5, 10, 30, 60, or any multiple
* of 60. High-resolution metrics are those metrics stored by a PutMetricData
call that
* includes a StorageResolution
of 1 second.
*
* If the StartTime
parameter specifies a time stamp that is greater than 3 hours ago, you must
* specify the period as follows or no data points in that time range is returned:
*
*
* -
*
* Start time between 3 hours and 15 days ago - Use a multiple of 60 seconds (1 minute).
*
*
* -
*
* Start time between 15 and 63 days ago - Use a multiple of 300 seconds (5 minutes).
*
*
* -
*
* Start time greater than 63 days ago - Use a multiple of 3600 seconds (1 hour).
*
*
*/
public final Integer period() {
return period;
}
/**
*
* The metric statistics, other than percentile. For percentile statistics, use ExtendedStatistics
.
* When calling GetMetricStatistics
, you must specify either Statistics
or
* ExtendedStatistics
, but not both.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasStatistics} method.
*
*
* @return The metric statistics, other than percentile. For percentile statistics, use
* ExtendedStatistics
. When calling GetMetricStatistics
, you must specify either
* Statistics
or ExtendedStatistics
, but not both.
*/
public final List statistics() {
return StatisticsCopier.copyStringToEnum(statistics);
}
/**
* For responses, this returns true if the service returned a value for the Statistics property. This DOES NOT check
* that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is
* useful because the SDK will never return a null collection or map, but you may need to differentiate between the
* service returning nothing (or null) and the service returning an empty collection or map. For requests, this
* returns true if a value for the property was specified in the request builder, and false if a value was not
* specified.
*/
public final boolean hasStatistics() {
return statistics != null && !(statistics instanceof SdkAutoConstructList);
}
/**
*
* The metric statistics, other than percentile. For percentile statistics, use ExtendedStatistics
.
* When calling GetMetricStatistics
, you must specify either Statistics
or
* ExtendedStatistics
, but not both.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasStatistics} method.
*
*
* @return The metric statistics, other than percentile. For percentile statistics, use
* ExtendedStatistics
. When calling GetMetricStatistics
, you must specify either
* Statistics
or ExtendedStatistics
, but not both.
*/
public final List statisticsAsStrings() {
return statistics;
}
/**
* For responses, this returns true if the service returned a value for the ExtendedStatistics property. This DOES
* NOT check that the value is non-empty (for which, you should check the {@code isEmpty()} method on the property).
* This is useful because the SDK will never return a null collection or map, but you may need to differentiate
* between the service returning nothing (or null) and the service returning an empty collection or map. For
* requests, this returns true if a value for the property was specified in the request builder, and false if a
* value was not specified.
*/
public final boolean hasExtendedStatistics() {
return extendedStatistics != null && !(extendedStatistics instanceof SdkAutoConstructList);
}
/**
*
* The percentile statistics. Specify values between p0.0 and p100. When calling GetMetricStatistics
,
* you must specify either Statistics
or ExtendedStatistics
, but not both. Percentile
* statistics are not available for metrics when any of the metric values are negative numbers.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* This method will never return null. If you would like to know whether the service returned this field (so that
* you can differentiate between null and empty), you can use the {@link #hasExtendedStatistics} method.
*
*
* @return The percentile statistics. Specify values between p0.0 and p100. When calling
* GetMetricStatistics
, you must specify either Statistics
or
* ExtendedStatistics
, but not both. Percentile statistics are not available for metrics when
* any of the metric values are negative numbers.
*/
public final List extendedStatistics() {
return extendedStatistics;
}
/**
*
* The unit for a given metric. If you omit Unit
, all data that was collected with any unit is
* returned, along with the corresponding units that were specified when the data was reported to CloudWatch. If you
* specify a unit, the operation returns only data that was collected with that unit specified. If you specify a
* unit that does not match the data collected, the results of the operation are null. CloudWatch does not perform
* unit conversions.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #unit} will return
* {@link StandardUnit#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #unitAsString}.
*
*
* @return The unit for a given metric. If you omit Unit
, all data that was collected with any unit is
* returned, along with the corresponding units that were specified when the data was reported to
* CloudWatch. If you specify a unit, the operation returns only data that was collected with that unit
* specified. If you specify a unit that does not match the data collected, the results of the operation are
* null. CloudWatch does not perform unit conversions.
* @see StandardUnit
*/
public final StandardUnit unit() {
return StandardUnit.fromValue(unit);
}
/**
*
* The unit for a given metric. If you omit Unit
, all data that was collected with any unit is
* returned, along with the corresponding units that were specified when the data was reported to CloudWatch. If you
* specify a unit, the operation returns only data that was collected with that unit specified. If you specify a
* unit that does not match the data collected, the results of the operation are null. CloudWatch does not perform
* unit conversions.
*
*
* If the service returns an enum value that is not available in the current SDK version, {@link #unit} will return
* {@link StandardUnit#UNKNOWN_TO_SDK_VERSION}. The raw value returned by the service is available from
* {@link #unitAsString}.
*
*
* @return The unit for a given metric. If you omit Unit
, all data that was collected with any unit is
* returned, along with the corresponding units that were specified when the data was reported to
* CloudWatch. If you specify a unit, the operation returns only data that was collected with that unit
* specified. If you specify a unit that does not match the data collected, the results of the operation are
* null. CloudWatch does not perform unit conversions.
* @see StandardUnit
*/
public final String unitAsString() {
return unit;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + super.hashCode();
hashCode = 31 * hashCode + Objects.hashCode(namespace());
hashCode = 31 * hashCode + Objects.hashCode(metricName());
hashCode = 31 * hashCode + Objects.hashCode(hasDimensions() ? dimensions() : null);
hashCode = 31 * hashCode + Objects.hashCode(startTime());
hashCode = 31 * hashCode + Objects.hashCode(endTime());
hashCode = 31 * hashCode + Objects.hashCode(period());
hashCode = 31 * hashCode + Objects.hashCode(hasStatistics() ? statisticsAsStrings() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasExtendedStatistics() ? extendedStatistics() : null);
hashCode = 31 * hashCode + Objects.hashCode(unitAsString());
return hashCode;
}
@Override
public final boolean equals(Object obj) {
return super.equals(obj) && equalsBySdkFields(obj);
}
@Override
public final boolean equalsBySdkFields(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof GetMetricStatisticsRequest)) {
return false;
}
GetMetricStatisticsRequest other = (GetMetricStatisticsRequest) obj;
return Objects.equals(namespace(), other.namespace()) && Objects.equals(metricName(), other.metricName())
&& hasDimensions() == other.hasDimensions() && Objects.equals(dimensions(), other.dimensions())
&& Objects.equals(startTime(), other.startTime()) && Objects.equals(endTime(), other.endTime())
&& Objects.equals(period(), other.period()) && hasStatistics() == other.hasStatistics()
&& Objects.equals(statisticsAsStrings(), other.statisticsAsStrings())
&& hasExtendedStatistics() == other.hasExtendedStatistics()
&& Objects.equals(extendedStatistics(), other.extendedStatistics())
&& Objects.equals(unitAsString(), other.unitAsString());
}
/**
* Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be
* redacted from this string using a placeholder value.
*/
@Override
public final String toString() {
return ToString.builder("GetMetricStatisticsRequest").add("Namespace", namespace()).add("MetricName", metricName())
.add("Dimensions", hasDimensions() ? dimensions() : null).add("StartTime", startTime()).add("EndTime", endTime())
.add("Period", period()).add("Statistics", hasStatistics() ? statisticsAsStrings() : null)
.add("ExtendedStatistics", hasExtendedStatistics() ? extendedStatistics() : null).add("Unit", unitAsString())
.build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Namespace":
return Optional.ofNullable(clazz.cast(namespace()));
case "MetricName":
return Optional.ofNullable(clazz.cast(metricName()));
case "Dimensions":
return Optional.ofNullable(clazz.cast(dimensions()));
case "StartTime":
return Optional.ofNullable(clazz.cast(startTime()));
case "EndTime":
return Optional.ofNullable(clazz.cast(endTime()));
case "Period":
return Optional.ofNullable(clazz.cast(period()));
case "Statistics":
return Optional.ofNullable(clazz.cast(statisticsAsStrings()));
case "ExtendedStatistics":
return Optional.ofNullable(clazz.cast(extendedStatistics()));
case "Unit":
return Optional.ofNullable(clazz.cast(unitAsString()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function