Class CloudWatchMetricPublisher.Builder
- Enclosing class:
CloudWatchMetricPublisher
CloudWatchMetricPublisher
instances. See the individual properties for which
configuration settings are available.-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build aCloudWatchMetricPublisher
using the configuration currently configured on this publisher.Configure theCloudWatchAsyncClient
instance that should be used to communicate with CloudWatch.detailedMetrics
(Collection<SdkMetric<?>> detailedMetrics) Configure the set of metrics for which detailed values and counts are uploaded to CloudWatch, instead of summaries.detailedMetrics
(SdkMetric<?>... detailedMetrics) dimensions
(Collection<SdkMetric<String>> dimensions) dimensions
(SdkMetric<String>... dimensions) maximumCallsPerUpload
(Integer maximumCallsPerUpload) Configure the maximum number ofCloudWatchAsyncClient.putMetricData(PutMetricDataRequest)
calls that an individual "upload" event can make to CloudWatch.metricCategories
(Collection<MetricCategory> metricCategories) Configure theMetricCategory
s that should be uploaded to CloudWatch.metricCategories
(MetricCategory... metricCategories) metricLevel
(MetricLevel metricLevel) Configure theMetricLevel
that should be uploaded to CloudWatch.Configure thePutMetricDataRequest.namespace()
used for all put-metric-data calls from this publisher.uploadFrequency
(Duration uploadFrequency) Configure the frequency at which aggregated metrics are uploaded to CloudWatch and released from memory.
-
Method Details
-
namespace
Configure thePutMetricDataRequest.namespace()
used for all put-metric-data calls from this publisher.If this is not specified,
AwsSdk/JavaSdk2
will be used. -
cloudWatchClient
Configure theCloudWatchAsyncClient
instance that should be used to communicate with CloudWatch.If this is not specified, the
CloudWatchAsyncClient
will be created viaCloudWatchAsyncClient.create()
(and will be closed whenCloudWatchMetricPublisher.close()
is invoked).If you specify a
CloudWatchAsyncClient
via this method, it will not be closed when this publisher is closed. You will need to need to manage the lifecycle of the client yourself. -
uploadFrequency
Configure the frequency at which aggregated metrics are uploaded to CloudWatch and released from memory.If this is not specified, metrics will be uploaded once per minute.
Smaller values will: (1) reduce the amount of memory used by the library (particularly when
detailedMetrics(Collection)
are enabled), (2) increase the number of CloudWatch calls (and therefore increase CloudWatch usage cost).Larger values will: (1) increase the amount of memory used by the library (particularly when
detailedMetrics
are enabled), (2) increase the time it takes for metric data to appear in CloudWatch, (3) reduce the number of CloudWatch calls (and therefore decrease CloudWatch usage cost).Warning: When
detailedMetrics
are enabled, all unique metric values are stored in memory until they can be published to CloudWatch. A highuploadFrequency
with multipledetailedMetrics
enabled can quickly consume heap memory while the values wait to be published to CloudWatch. In memory constrained environments, it is recommended to minimize the number ofdetailedMetrics
configured on the publisher, or to upload metric data more frequently. As with all performance and resource concerns, profiling in a production-like environment is encouraged. -
maximumCallsPerUpload
Configure the maximum number ofCloudWatchAsyncClient.putMetricData(PutMetricDataRequest)
calls that an individual "upload" event can make to CloudWatch. Any metrics that would exceed this limit are dropped during the upload, logging a warning on thesoftware.amazon.awssdk.metrics.publishers.cloudwatch
namespace.The SDK will always attempt to maximize the number of metrics per put-metric-data call, but uploads will be split into multiple put-metric-data calls if they include a lot of different metrics or if there are a lot of high-value- distribution
detailedMetrics(Collection)
being monitored.This value combined with the
uploadFrequency(Duration)
effectively provide a "hard cap" on the number of put-metric-data calls, to prevent unbounded cost in the event that too many metrics are enabled by the user.If this is not specified, put-metric-data calls will be capped at 10 per upload.
-
dimensions
Configure theSdkMetric
s that are used to define theDimension
s metrics are aggregated under.If this is not specified,
CoreMetric.SERVICE_ID
andCoreMetric.OPERATION_NAME
are used, allowing you to compare metrics for different services and operations.Warning: Configuring the dimensions incorrectly can result in a large increase in the number of unique metrics and put-metric-data calls to cloudwatch, which have an associated monetary cost. Be sure you're choosing your metric dimensions wisely, and that you always evaluate the cost of modifying these values on your monthly usage costs.
Example useful settings:
CoreMetric.SERVICE_ID
andCoreMetric.OPERATION_NAME
(default): Separate metrics by service and operation, so that you can compare latencies between AWS services and operations.CoreMetric.SERVICE_ID
,CoreMetric.OPERATION_NAME
andCoreMetric.HOST_NAME
: Separate metrics by service, operation and host so that you can compare latencies across hosts in your fleet. Note: This should only be used when your fleet is relatively small. Large fleets result in a large number of unique metrics being generated.CoreMetric.SERVICE_ID
,CoreMetric.OPERATION_NAME
andHttpMetric.HTTP_CLIENT_NAME
: Separate metrics by service, operation and HTTP client type so that you can compare latencies between different HTTP client implementations.
-
dimensions
@SafeVarargs public final CloudWatchMetricPublisher.Builder dimensions(SdkMetric<String>... dimensions) - See Also:
-
metricCategories
public CloudWatchMetricPublisher.Builder metricCategories(Collection<MetricCategory> metricCategories) Configure theMetricCategory
s that should be uploaded to CloudWatch.If this is not specified,
MetricCategory.ALL
is used.All
SdkMetric
s are associated with at least oneMetricCategory
. This setting determines which category of metrics uploaded to CloudWatch. Any metricsCloudWatchMetricPublisher.publish(MetricCollection)
ed that do not fall under these configured categories are ignored.Note: If there are
dimensions(Collection)
configured that do not fall under theseMetricCategory
values, the dimensions will NOT be ignored. In other words, the metric category configuration only affects which metrics are uploaded to CloudWatch, not which values can be used fordimensions
. -
metricCategories
- See Also:
-
metricLevel
Configure theMetricLevel
that should be uploaded to CloudWatch.If this is not specified,
MetricLevel.INFO
is used.All
SdkMetric
s are associated with oneMetricLevel
. This setting determines which level of metrics uploaded to CloudWatch. Any metricsCloudWatchMetricPublisher.publish(MetricCollection)
ed that do not fall under these configured categories are ignored.Note: If there are
dimensions(Collection)
configured that do not fall under thisMetricLevel
values, the dimensions will NOT be ignored. In other words, the metric category configuration only affects which metrics are uploaded to CloudWatch, not which values can be used fordimensions
. -
detailedMetrics
Configure the set of metrics for which detailed values and counts are uploaded to CloudWatch, instead of summaries.By default, all metrics published to this publisher are summarized using
StatisticSet
s. This saves memory, because it allows the publisher to store a fixed amount of information in memory, no matter how many different metric values are published. The drawback is that metrics other than count, sum, average, maximum and minimum are not made available in CloudWatch. ThedetailedMetrics
setting instructs the publisher to store and publish itemizedMetricDatum.values()
andMetricDatum.counts()
, which enables other metrics like p90 and p99 to be queried in CloudWatch.Warning: When
detailedMetrics
are enabled, all unique metric values are stored in memory until they can be published to CloudWatch. A highuploadFrequency
with multipledetailedMetrics
enabled can quickly consume heap memory while the values wait to be published to CloudWatch. In memory constrained environments, it is recommended to minimize the number ofdetailedMetrics
configured on the publisher, or to upload metric data more frequently. As with all performance and resource concerns, profiling in a production-like environment is encouraged.In addition to additional heap memory usage, detailed metrics can result in more requests being sent to CloudWatch, which can also introduce additional usage cost. The
maximumCallsPerUpload(Integer)
acts as a safeguard against too many calls being made, but if you configure multipledetailedMetrics
, you may need to increase themaximumCallsPerUpload
limit. -
detailedMetrics
- See Also:
-
build
Build aCloudWatchMetricPublisher
using the configuration currently configured on this publisher.
-