java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.services.cloudwatch.Metric
All Implemented Interfaces:
IMetric, software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:36.874Z") @Stability(Stable) public class Metric extends software.amazon.jsii.JsiiObject implements IMetric
A metric emitted by a service.

The metric is a combination of a metric identifier (namespace, name and dimensions) and an aggregation function (statistic, period and unit).

It also contains metadata which is used only in graphs, such as color and label. It makes sense to embed this in here, so that compound constructs can attach that metadata to metrics they expose.

This class does not represent a resource, so hence is not a construct. Instead, Metric is an abstraction that makes it easy to specify metrics for use in both alarms and graphs.

Example:

 Function fn;
 Metric minuteErrorRate = fn.metricErrors(MetricOptions.builder()
         .statistic("avg")
         .period(Duration.minutes(1))
         .label("Lambda failure rate")
         .build());
 
  • Constructor Details

    • Metric

      protected Metric(software.amazon.jsii.JsiiObjectRef objRef)
    • Metric

      protected Metric(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Metric

      @Stability(Stable) public Metric(@NotNull MetricProps props)
      Parameters:
      props - This parameter is required.
  • Method Details

    • grantPutMetricData

      @Stability(Stable) @NotNull public static Grant grantPutMetricData(@NotNull IGrantable grantee)
      Grant permissions to the given identity to write metrics.

      Parameters:
      grantee - The IAM identity to give permissions to. This parameter is required.
    • attachTo

      @Stability(Stable) @NotNull public Metric attachTo(@NotNull software.constructs.IConstruct scope)
      Attach the metric object to the given construct scope.

      Returns a Metric object that uses the account and region from the Stack the given construct is defined in. If the metric is subsequently used in a Dashboard or Alarm in a different Stack defined in a different account or region, the appropriate 'region' and 'account' fields will be added to it.

      If the scope we attach to is in an environment-agnostic stack, nothing is done and the same Metric object is returned.

      Parameters:
      scope - This parameter is required.
    • createAlarm

      @Stability(Stable) @NotNull public Alarm createAlarm(@NotNull Construct scope, @NotNull String id, @NotNull CreateAlarmOptions props)
      Make a new Alarm for this metric.

      Combines both properties that may adjust the metric (aggregation) as well as alarm properties.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
    • toAlarmConfig

      @Stability(Deprecated) @Deprecated @NotNull public MetricAlarmConfig toAlarmConfig()
      Deprecated.
      use toMetricConfig()
      (deprecated) Turn this metric object into an alarm configuration.

      Specified by:
      toAlarmConfig in interface IMetric
    • toGraphConfig

      @Stability(Deprecated) @Deprecated @NotNull public MetricGraphConfig toGraphConfig()
      Deprecated.
      use toMetricConfig()
      (deprecated) Turn this metric object into a graph configuration.

      Specified by:
      toGraphConfig in interface IMetric
    • toMetricConfig

      @Stability(Stable) @NotNull public MetricConfig toMetricConfig()
      Inspect the details of the metric object.
      Specified by:
      toMetricConfig in interface IMetric
    • toString

      @Stability(Stable) @NotNull public String toString()
      Returns a string representation of an object.
      Overrides:
      toString in class Object
    • with

      @Stability(Stable) @NotNull public Metric with(@NotNull MetricOptions props)
      Return a copy of Metric with properties changed.

      All properties except namespace and metricName can be changed.

      Parameters:
      props - The set of properties to change. This parameter is required.
    • getMetricName

      @Stability(Stable) @NotNull public String getMetricName()
      Name of this metric.
    • getNamespace

      @Stability(Stable) @NotNull public String getNamespace()
      Namespace of this metric.
    • getPeriod

      @Stability(Stable) @NotNull public Duration getPeriod()
      Period of this metric.
    • getStatistic

      @Stability(Stable) @NotNull public String getStatistic()
      Statistic of this metric.
    • getAccount

      @Stability(Stable) @Nullable public String getAccount()
      Account which this metric comes from.
    • getColor

      @Stability(Stable) @Nullable public String getColor()
      The hex color code used when this metric is rendered on a graph.
    • getDimensions

      @Stability(Stable) @Nullable public Map<String,Object> getDimensions()
      Dimensions of this metric.
    • getLabel

      @Stability(Stable) @Nullable public String getLabel()
      Label for this metric when added to a Graph in a Dashboard.
    • getRegion

      @Stability(Stable) @Nullable public String getRegion()
      Region which this metric comes from.
    • getUnit

      @Stability(Stable) @Nullable public Unit getUnit()
      Unit of the metric.
    • getWarnings

      @Stability(Stable) @Nullable public List<String> getWarnings()
      Warnings attached to this metric.
      Specified by:
      getWarnings in interface IMetric