Package software.amazon.awssdk.metrics
Class LoggingMetricPublisher
java.lang.Object
software.amazon.awssdk.metrics.LoggingMetricPublisher
- All Implemented Interfaces:
AutoCloseable
,MetricPublisher
,SdkAutoCloseable
An implementation of
MetricPublisher
that logs all published metrics under the
software.amazon.awssdk.metrics.LoggingMetricPublisher
namespace.
LoggingMetricPublisher
can be configured with a Level
to control the log level at which metrics are recorded
and a LoggingMetricPublisher.Format
to control the format that metrics are printed in.
LoggingMetricPublisher.Format.PLAIN
can 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.PRETTY
can 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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
static LoggingMetricPublisher
create()
Create aLoggingMetricPublisher
with the default configuration ofLevel.INFO
andLoggingMetricPublisher.Format.PLAIN
.static LoggingMetricPublisher
create
(org.slf4j.event.Level logLevel, LoggingMetricPublisher.Format format) void
publish
(MetricCollection metrics) Notify the publisher of new metric data.
-
Method Details
-
create
Create aLoggingMetricPublisher
with the default configuration ofLevel.INFO
andLoggingMetricPublisher.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
Description copied from interface:MetricPublisher
Notify the publisher of new metric data. After this call returns, the caller can safely discard the givenmetricCollection
instance 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
null
metricCollection
, 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:
publish
in interfaceMetricPublisher
- Parameters:
metrics
- The collection of metrics.
-
close
public void close()Description copied from interface:MetricPublisher
Important: Implementations must block the calling thread until all pending metrics are published and any resources acquired have been freed.
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceMetricPublisher
- Specified by:
close
in interfaceSdkAutoCloseable
-