Package software.amazon.awssdk.metrics
Class LoggingMetricPublisher
- java.lang.Object
-
- software.amazon.awssdk.metrics.LoggingMetricPublisher
-
- All Implemented Interfaces:
AutoCloseable,MetricPublisher,SdkAutoCloseable
@SdkPublicApi public final class LoggingMetricPublisher extends Object implements MetricPublisher
An implementation ofMetricPublisherthat logs all published metrics under thesoftware.amazon.awssdk.metrics.LoggingMetricPublishernamespace.LoggingMetricPublishercan be configured with aLevelto control the log level at which metrics are recorded and aLoggingMetricPublisher.Formatto control the format that metrics are printed in.LoggingMetricPublisher.Format.PLAINcan be used to print all metrics on a single line. E.g.,Metrics published: MetricCollection(name=ApiCall, metrics=[MetricRecord(metric=MarshallingDuration, value=PT0.000202197S), MetricRecord(metric=RetryCount, value=0), MetricRecord(metric=ApiCallSuccessful, value=true), MetricRecord(metric=OperationName, value=HeadObject), MetricRecord(metric=ApiCallDuration, value=PT0.468369S), MetricRecord(metric=CredentialsFetchDuration, value=PT0.000003191S), MetricRecord(metric=ServiceId, value=S3)], children=[MetricCollection(name=ApiCallAttempt, metrics=[MetricRecord(metric=SigningDuration, value=PT0.000667268S), MetricRecord(metric=ServiceCallDuration, value=PT0.460529977S), MetricRecord(metric=AwsExtendedRequestId, value=jY/Co5Ge6WjRYk78kGOYQ4Z/CqUBr6pAAPZtexgOQR3Iqs3QP0OfZz3fDraQiXtmx7eXCZ4sbO0=), MetricRecord(metric=HttpStatusCode, value=200), MetricRecord(metric=BackoffDelayDuration, value=PT0S), MetricRecord(metric=AwsRequestId, value=6SJ82R65SADHX098)], children=[MetricCollection(name=HttpClient, metrics=[MetricRecord(metric=AvailableConcurrency, value=0), MetricRecord(metric=LeasedConcurrency, value=0), MetricRecord(metric=ConcurrencyAcquireDuration, value=PT0.230757S), MetricRecord(metric=PendingConcurrencyAcquires, value=0), MetricRecord(metric=MaxConcurrency, value=50), MetricRecord(metric=HttpClientName, value=NettyNio)], children=[])])])
LoggingMetricPublisher.Format.PRETTYcan be used to print metrics over multiple lines in a readable fashion suitable for debugging. E.g.,[18e5092e] ApiCall [18e5092e] ┌────────────────────────────────────────┐ [18e5092e] │ MarshallingDuration=PT0.000227427S │ [18e5092e] │ RetryCount=0 │ [18e5092e] │ ApiCallSuccessful=true │ [18e5092e] │ OperationName=HeadObject │ [18e5092e] │ ApiCallDuration=PT0.541751S │ [18e5092e] │ CredentialsFetchDuration=PT0.00000306S │ [18e5092e] │ ServiceId=S3 │ [18e5092e] └────────────────────────────────────────┘ [18e5092e] ApiCallAttempt [18e5092e] ┌───────────────────────────────────────────────────────────────────────────────────────────────────┐ [18e5092e] │ SigningDuration=PT0.000974924S │ [18e5092e] │ ServiceCallDuration=PT0.531462375S │ [18e5092e] │ AwsExtendedRequestId=eGfwjV3mSwQZQD4YxHLswYguvhQoGcDTkr2jRvpio37a6QmhWd18C8wagC8LkBzzcnOOKoMuiXw= │ [18e5092e] │ HttpStatusCode=200 │ [18e5092e] │ BackoffDelayDuration=PT0S │ [18e5092e] │ AwsRequestId=ED46TP7NN62DDG4Q │ [18e5092e] └───────────────────────────────────────────────────────────────────────────────────────────────────┘ [18e5092e] HttpClient [18e5092e] ┌────────────────────────────────────────┐ [18e5092e] │ AvailableConcurrency=0 │ [18e5092e] │ LeasedConcurrency=0 │ [18e5092e] │ ConcurrencyAcquireDuration=PT0.235851S │ [18e5092e] │ PendingConcurrencyAcquires=0 │ [18e5092e] │ MaxConcurrency=50 │ [18e5092e] │ HttpClientName=NettyNio │ [18e5092e] └────────────────────────────────────────┘
Note that the output format may be subject to small changes in future versions and should not be relied upon as a strict public contract.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLoggingMetricPublisher.Format
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()static LoggingMetricPublishercreate()Create aLoggingMetricPublisherwith the default configuration ofLevel.INFOandLoggingMetricPublisher.Format.PLAIN.static LoggingMetricPublishercreate(org.slf4j.event.Level logLevel, LoggingMetricPublisher.Format format)voidpublish(MetricCollection metrics)Notify the publisher of new metric data.
-
-
-
Method Detail
-
create
public static LoggingMetricPublisher create()
Create aLoggingMetricPublisherwith the default configuration ofLevel.INFOandLoggingMetricPublisher.Format.PLAIN.
-
create
public static LoggingMetricPublisher create(org.slf4j.event.Level logLevel, LoggingMetricPublisher.Format format)
- Parameters:
logLevel- the SLF4J log level to log metrics withformat- the format to print the metrics with (see class-level documentation for examples)
-
publish
public void publish(MetricCollection metrics)
Description copied from interface:MetricPublisherNotify the publisher of new metric data. After this call returns, the caller can safely discard the givenmetricCollectioninstance if it no longer needs it. Implementations are strongly encouraged to complete any further aggregation and publishing of metrics in an asynchronous manner to avoid blocking the calling thread.With the exception of a
nullmetricCollection, all invocations of this method must return normally. This is to ensure that callers of the publisher can safely assume that even in situations where an error happens during publishing that it will not interrupt the calling thread.- Specified by:
publishin interfaceMetricPublisher- Parameters:
metrics- The collection of metrics.
-
close
public void close()
Description copied from interface:MetricPublisherImportant: Implementations must block the calling thread until all pending metrics are published and any resources acquired have been freed.
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceMetricPublisher- Specified by:
closein interfaceSdkAutoCloseable
-
-