Enum AwsSdkMetrics

java.lang.Object
java.lang.Enum<AwsSdkMetrics>
com.amazonaws.metrics.AwsSdkMetrics
All Implemented Interfaces:
Serializable, Comparable<AwsSdkMetrics>, java.lang.constant.Constable

public enum AwsSdkMetrics extends Enum<AwsSdkMetrics>
Used to control the default AWS SDK metric collection system.

The default metric collection of the Java AWS SDK is disabled by default. To enable it, simply specify the system property "com.amazonaws.sdk.enableDefaultMetrics" when starting up the JVM. When the system property is specified, a default metric collector will be started at the AWS SDK level. The default implementation uploads the request/response metrics captured to Amazon CloudWatch using AWS credentials obtained via the DefaultAWSCredentialsProviderChain.

For additional optional attributes that can be specified for the system property, please read the javadoc of the individual fields of this class for more details.

Instead of via system properties, the default AWS SDK metric collection can also be enabled programmatically via enableDefaultMetrics(). Similarly, metric collection at the AWS SDK level can be disabled via disableMetrics().

Clients who needs to fully customize the metric collection can implement the SPI MetricCollector, and then replace the default AWS SDK implementation of the collector via setMetricCollector(MetricCollector).

Alternatively, for limited customization of the internal collector implementation provided by the AWS SDK, one can extend the internal Amazon CloudWatch metric collector. See the javadoc at com.amazonaws.metrics.internal.cloudwatch.CloudWatchMetricConfig for more details.

  • Field Details

    • DEFAULT_METRIC_NAMESPACE

      public static final String DEFAULT_METRIC_NAMESPACE
      See Also:
    • USE_SINGLE_METRIC_NAMESPACE

      public static final String USE_SINGLE_METRIC_NAMESPACE
      Used to enable the use of a single metric namespace for all levels of SDK generated CloudWatch metrics such as JVM level, host level, etc.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=useSingleMetricNamespace
       
      See Also:
    • EXCLUDE_MACHINE_METRICS

      public static final String EXCLUDE_MACHINE_METRICS
      Used to exclude the generation of JVM metrics when the AWS SDK default metrics is enabled. By default, jvm metrics is included.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=excludeJvmMetrics
       
      See Also:
    • INCLUDE_PER_HOST_METRICS

      public static final String INCLUDE_PER_HOST_METRICS
      Used to generate per host level metrics when the AWS SDK default metrics is enabled. By default, per-host level metrics is excluded.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=includePerHostMetrics
       
      See Also:
    • AWS_CREDENTAIL_PROPERTIES_FILE

      public static final String AWS_CREDENTAIL_PROPERTIES_FILE
      Deprecated.
      Used to specify an AWS credential property file. By default, the DefaultAWSCredentialsProviderChain is used.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=credentialFile=/path/aws.properties
       
      See Also:
    • AWS_CREDENTIAL_PROPERTIES_FILE

      public static final String AWS_CREDENTIAL_PROPERTIES_FILE
      Used to specify an AWS credential property file. By default, the DefaultAWSCredentialsProviderChain is used.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=credentialFile=/path/aws.properties
       
      See Also:
    • CLOUDWATCH_REGION

      public static final String CLOUDWATCH_REGION
      Used to specify the Amazon CloudWatch region for metrics uploading purposes. By default, metrics are uploaded to us-east-1.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=cloudwatchRegion=us-west-2
       
      See Also:
    • METRIC_QUEUE_SIZE

      public static final String METRIC_QUEUE_SIZE
      Used to specify the internal in-memory queue size for queuing metrics data points. The default size is 1,000.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=metricQueueSize=1000
       
      See Also:
    • QUEUE_POLL_TIMEOUT_MILLI

      public static final String QUEUE_POLL_TIMEOUT_MILLI
      Used to specify the internal queue polling timeout in millisecond. The default timeout is 1 minute, which is optimal for the default CloudWatch implementation.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=getQueuePollTimeoutMilli=60000
       
      See Also:
    • METRIC_NAME_SPACE

      public static final String METRIC_NAME_SPACE
      Used to specify a custom metric name space. The default name space is DEFAULT_METRIC_NAMESPACE.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=metricNameSpace=MyNameSpace
       
      See Also:
    • JVM_METRIC_NAME

      public static final String JVM_METRIC_NAME
      Used to generate per JVM level metrics when the AWS SDK default metrics is enabled. By default, JVM level metrics are not generated.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=jvmMetricName=Tomcat1
       
      See Also:
    • HOST_METRIC_NAME

      public static final String HOST_METRIC_NAME
      Used to explicitly specify the host name for metric purposes, instead of detecting the host name via InetAddress when the AWS SDK default metrics is enabled. Specifying the host name also has the side effecting of enabling per host level metrics.
       Example:
        -Dcom.amazonaws.sdk.enableDefaultMetrics=hostMetricName=MyHost
       
      See Also:
  • Method Details

    • values

      public static AwsSdkMetrics[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static AwsSdkMetrics valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null
    • isMetricAdminMBeanRegistered

      public static boolean isMetricAdminMBeanRegistered()
      Returns true if the metric admin MBean is currently registered for JMX access; false otherwise.
    • getRegisteredAdminMbeanName

      public static String getRegisteredAdminMbeanName()
      Returns the name of the registered admin mbean; or null if the admin mbean is not currently registered.
    • registerMetricAdminMBean

      public static boolean registerMetricAdminMBean()
      Registers the metric admin MBean for JMX access for the current classloader. If an AdminMbean is found to have been registered under a different class loader, the AdminMBean of the current class loader would be registered under the same name MBEAN_OBJECT_NAME but with an additional suffix in the format of "/", where count is a counter incrementing from 1.
      Returns:
      true if the registeration succeeded; false otherwise.
    • unregisterMetricAdminMBean

      public static boolean unregisterMetricAdminMBean()
      Unregisters the metric admin MBean from JMX for the current classloader.
      Returns:
      true if the unregistration succeeded or if there is no admin MBean registered; false otherwise.
    • getRequestMetricCollector

      public static <T extends RequestMetricCollector> T getRequestMetricCollector()
      Returns a non-null request metric collector for the SDK. If no custom request metric collector has previously been specified via setMetricCollector(MetricCollector) and the SDKGlobalConfiguration.DEFAULT_METRICS_SYSTEM_PROPERTY has been set, then this method will initialize and return the default metric collector provided by the AWS SDK on a best-attempt basis.
    • getServiceMetricCollector

      public static <T extends ServiceMetricCollector> T getServiceMetricCollector()
    • getMetricCollector

      public static <T extends MetricCollector> T getMetricCollector()
    • setMetricCollector

      public static void setMetricCollector(MetricCollector mc)
      Sets the metric collector to be used by the AWS SDK, and stop the previously running collector used by the AWS SDK, if any. Note, however, a request metric collector specified at the web service client level or request level, if any, always takes precedence over the one specified at the AWS SDK level.

      Caller of this method is responsible for starting the new metric collector specified as the input parameter.

      Parameters:
      mc - the metric collector to be used by the AWS SDK; or null if no metric collection is to be performed at the AWS SDK level.
      See Also:
    • setMachineMetricsExcluded

      public static void setMachineMetricsExcluded(boolean excludeMachineMetrics)
      Used to set whether the machine metrics is to be excluded.
      Parameters:
      excludeMachineMetrics - true if machine metrics is to be excluded; false otherwise.
    • setPerHostMetricsIncluded

      public static void setPerHostMetricsIncluded(boolean includePerHostMetrics)
      Used to set whether the per-host metrics is to be included.
      Parameters:
      includePerHostMetrics - true if per-host metrics is to be included; false otherwise.
    • enableHttpSocketReadMetric

      public static void enableHttpSocketReadMetric()
      Used to enable AWSRequestMetrics.Field.HttpSocketReadTime metric since by default it is disabled.
    • isDefaultMetricsEnabled

      public static boolean isDefaultMetricsEnabled()
      Returns true if the system property SDKGlobalConfiguration.DEFAULT_METRICS_SYSTEM_PROPERTY has been set; false otherwise.
    • isSingleMetricNamespace

      public static boolean isSingleMetricNamespace()
      Returns true if a single metric name space is to be used for all levels of SDK generated CloudWatch metrics, including JVM level, host level, etc.; false otherwise.
    • setSingleMetricNamespace

      public static void setSingleMetricNamespace(boolean singleMetricNamespace)
      Used to set whether a single metric name space is to be used for all levels of SDK generated CloudWatch metrics, including JVM level, host level, etc.
      Parameters:
      singleMetricNamespace - true if single metric name is to be used; false otherwise.
    • isMetricsEnabled

      public static boolean isMetricsEnabled()
      Returns true if metrics at the AWS SDK level is enabled; false if disabled.
    • isMachineMetricExcluded

      public static boolean isMachineMetricExcluded()
      Returns true if machine metrics is to be excluded.
    • isPerHostMetricIncluded

      public static boolean isPerHostMetricIncluded()
      Returns true if the per-host metrics flag has been set; false otherwise.
    • isPerHostMetricEnabled

      public static boolean isPerHostMetricEnabled()
      Returns true if per-host metrics is enabled; false otherwise.
    • isHttpSocketReadMetricEnabled

      public static boolean isHttpSocketReadMetricEnabled()
      Returns true if HttpSocketReadMetric is enabled; false otherwise.
    • enableDefaultMetrics

      public static boolean enableDefaultMetrics()
      Starts the default AWS SDK metric collector, but only if no metric collector is currently in use at the AWS SDK level.
      Returns:
      true if the default AWS SDK metric collector has been successfully started by this call; false otherwise.
    • disableMetrics

      public static void disableMetrics()
      Convenient method to disable the metric collector at the AWS SDK level.
    • add

      public static boolean add(MetricType type)
      Adds the given metric type to the registry of predefined metrics to be captured at the AWS SDK level.
      Returns:
      true if the set of predefined metric types gets changed as a result of the call
    • addAll

      public static <T extends MetricType> boolean addAll(Collection<T> types)
      Adds the given metric types to the registry of predefined metrics to be captured at the AWS SDK level.
      Returns:
      true if the set of predefined metric types gets changed as a result of the call
    • set

      public static <T extends MetricType> void set(Collection<T> types)
      Sets the given metric types to replace the registry of predefined metrics to be captured at the AWS SDK level.
    • remove

      public static boolean remove(MetricType type)
      Removes the given metric type from the registry of predefined metrics to be captured at the AWS SDK level.
      Returns:
      true if the set of predefined metric types gets changed as a result of the call
    • getPredefinedMetrics

      public static Set<MetricType> getPredefinedMetrics()
      Returns an unmodifiable set of the current predefined metrics.
    • getCredentialProvider

      public static AWSCredentialsProvider getCredentialProvider()
      Returns the credential provider for the default AWS SDK metric implementation. This method is restricted to calls from the default AWS SDK metric implementation.
      Throws:
      SecurityException - if called outside the default AWS SDK metric implementation.
    • setCredentialProvider

      public static void setCredentialProvider(AWSCredentialsProvider provider)
      Sets the credential provider for the default AWS SDK metric implementation; or null if the default is to be used. Calling this method may result in the credential provider being different from the credential file property.
    • getRegion

      public static Regions getRegion()
      Returns the region configured for the default AWS SDK metric collector; or null if the default is to be used.
    • setRegion

      public static void setRegion(Regions region)
      Sets the region to be used for the default AWS SDK metric collector; or null if the default is to be used.
    • getCredentailFile

      public static String getCredentailFile()
      Returns the last set AWS credential file, or null if there is none.
    • setCredentialFile

      public static void setCredentialFile(String filepath) throws FileNotFoundException, IOException
      Sets the AWS credential file to be used for accessing Amazon CloudWatch. Successfully calling this method would result in the AWS credential provider to make use of the given credential file.
      Throws:
      FileNotFoundException
      IOException
    • getMetricQueueSize

      public static Integer getMetricQueueSize()
      Returns the internal metric queue size to be used for the default AWS SDK metric collector; or null if the default is to be used.
    • setMetricQueueSize

      public static void setMetricQueueSize(Integer size)
      Sets the metric queue size to be used for the default AWS SDK metric collector; or null if the default is to be used.
    • getQueuePollTimeoutMilli

      public static Long getQueuePollTimeoutMilli()
      Returns the internal metric queue timeout in millisecond to be used for the default AWS SDK metric collector; or null if the default is to be used.
    • setQueuePollTimeoutMilli

      public static void setQueuePollTimeoutMilli(Long timeoutMilli)
      Sets the queue poll time in millisecond to be used for the default AWS SDK metric collector; or null if the default is to be used.
    • getMetricNameSpace

      public static String getMetricNameSpace()
      Returns the metric name space, which is never null or blank.
    • setMetricNameSpace

      public static void setMetricNameSpace(String metricNameSpace)
      Sets the metric name space.
      Parameters:
      metricNameSpace - metric name space which must neither be null or blank.
      Throws:
      IllegalArgumentException - if the specified metric name space is either null or blank.
    • getJvmMetricName

      public static String getJvmMetricName()
      Returns the name of the JVM for generating per-JVM level metrics; or null or blank if per-JVM level metrics are disabled.
    • setJvmMetricName

      public static void setJvmMetricName(String jvmMetricName)
      Sets the name of the JVM for generating per-JVM level metrics.
      Parameters:
      jvmMetricName - name of the JVM for generating per-JVM level metrics; or null or blank if per-JVM level metrics are to be disabled.
    • getHostMetricName

      public static String getHostMetricName()
      Returns the host name for generating per-host level metrics; or null or blank if the host is to be automatically detected via InetAddress.
    • setHostMetricName

      public static void setHostMetricName(String hostMetricName)
      Sets the host name for generating per-host level metrics.
      Parameters:
      hostMetricName - host name for generating per-host level metrics; or null or blank if the host is to be automatically detected via InetAddress.