Class MetricsLogger


  • public class MetricsLogger
    extends java.lang.Object
    A metrics logger. Use this interface to publish logs to CloudWatch Logs and extract metrics to CloudWatch Metrics asynchronously.
    • Method Detail

      • flush

        public void flush()
        Flushes the current context state to the configured sink. TODO: Support flush asynchronously
      • putProperty

        public MetricsLogger putProperty​(java.lang.String key,
                                         java.lang.Object value)
        Set a property on the published metrics. This is stored in the emitted log data and you are not charged for this data by CloudWatch Metrics. These values can be values that are useful for searching on, but have too high cardinality to emit as dimensions to CloudWatch Metrics.
        Parameters:
        key - Property name
        value - Property value
        Returns:
        the current logger
      • putDimensions

        public MetricsLogger putDimensions​(DimensionSet dimensions)
        Adds a dimension. This is generally a low cardinality key-value pair that is part of the metric identity. CloudWatch treats each unique combination of dimensions as a separate metric, even if the metrics have the same metric name.
        Parameters:
        dimensions - the DimensionSet to add
        Returns:
        the current logger
        See Also:
        CloudWatch Dimensions
      • setDimensions

        public MetricsLogger setDimensions​(DimensionSet... dimensionSets)
        Overwrite all dimensions on this MetricsLogger instance.
        Parameters:
        dimensionSets - the dimensionSets to set
        Returns:
        the current logger
        See Also:
        CloudWatch Dimensions
      • setDimensions

        public MetricsLogger setDimensions​(boolean useDefault,
                                           DimensionSet... dimensionSets)
        Overwrite custom dimensions on this MetricsLogger instance, with an option to preserve default dimensions.
        Parameters:
        useDefault - indicates whether default dimensions should be used
        dimensionSets - the dimensionSets to set
        Returns:
        the current logger
      • resetDimensions

        public MetricsLogger resetDimensions​(boolean useDefault)
        Clear all custom dimensions on this MetricsLogger instance. Whether default dimensions should be used can be configured by the input parameter.
        Parameters:
        useDefault - indicates whether default dimensions should be used
        Returns:
        the current logger
      • putMetric

        public MetricsLogger putMetric​(java.lang.String key,
                                       double value,
                                       Unit unit)
                                throws InvalidMetricException
        Put a metric value. This value will be emitted to CloudWatch Metrics asynchronously and does not contribute to your account TPS limits. The value will also be available in your CloudWatch Logs
        Parameters:
        key - is the name of the metric
        value - is the value of the metric
        unit - is the unit of the metric value
        Returns:
        the current logger
        Throws:
        InvalidMetricException - if the metric is invalid
      • putMetric

        public MetricsLogger putMetric​(java.lang.String key,
                                       double value)
                                throws InvalidMetricException
        Put a metric value. This value will be emitted to CloudWatch Metrics asynchronously and does not contribute to your account TPS limits. The value will also be available in your CloudWatch Logs
        Parameters:
        key - the name of the metric
        value - the value of the metric
        Returns:
        the current logger
        Throws:
        InvalidMetricException - if the metric is invalid
      • putMetadata

        public MetricsLogger putMetadata​(java.lang.String key,
                                         java.lang.Object value)
        Add a custom key-value pair to the Metadata object.
        Parameters:
        key - the name of the key
        value - the value associated with the key
        Returns:
        the current logger
        See Also:
        CloudWatch Metadata
      • setNamespace

        public MetricsLogger setNamespace​(java.lang.String namespace)
                                   throws InvalidNamespaceException
        Set the CloudWatch namespace that metrics should be published to.
        Parameters:
        namespace - the namespace of the logs
        Returns:
        the current logger
        Throws:
        InvalidNamespaceException - if the namespace is invalid