public final class LoggingMetricPublisher extends Object implements MetricPublisher
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.
| Modifier and Type | Class and Description |
|---|---|
static class |
LoggingMetricPublisher.Format |
| Modifier and Type | Method and Description |
|---|---|
void |
close() |
static LoggingMetricPublisher |
create()
Create a
LoggingMetricPublisher with the default configuration of Level.INFO and LoggingMetricPublisher.Format.PLAIN. |
static LoggingMetricPublisher |
create(org.slf4j.event.Level logLevel,
LoggingMetricPublisher.Format format)
|
void |
publish(MetricCollection metrics)
Notify the publisher of new metric data.
|
public static LoggingMetricPublisher create()
LoggingMetricPublisher with the default configuration of Level.INFO and LoggingMetricPublisher.Format.PLAIN.public static LoggingMetricPublisher create(org.slf4j.event.Level logLevel, LoggingMetricPublisher.Format format)
logLevel - the SLF4J log level to log metrics withformat - the format to print the metrics with (see class-level documentation for examples)public void publish(MetricCollection metrics)
MetricPublishermetricCollection 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.
publish in interface MetricPublishermetrics - The collection of metrics.public void close()
MetricPublisherImportant: Implementations must block the calling thread until all pending metrics are published and any resources acquired have been freed.
close in interface AutoCloseableclose in interface MetricPublisherclose in interface SdkAutoCloseableCopyright © 2022. All rights reserved.