Class MathExpression

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

@Generated(value="jsii-pacmak/1.104.0 (build e79254c)", date="2024-10-31T19:12:54.642Z") @Stability(Stable) public class MathExpression extends software.amazon.jsii.JsiiObject implements IMetric
A math expression built with metric(s) emitted by a service.

The math expression is a combination of an expression (x+y) and metrics to apply expression on. 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.

MathExpression can also be used for search expressions. In this case, it also optionally accepts a searchRegion and searchAccount property for cross-environment search expressions.

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

Example:

 Function fn;
 MathExpression allProblems = MathExpression.Builder.create()
         .expression("errors + throttles")
         .usingMetrics(Map.of(
                 "errors", fn.metricErrors(),
                 "throttles", fn.metricThrottles()))
         .build();
 
  • Constructor Details

    • MathExpression

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

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

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

    • createAlarm

      @Stability(Stable) @NotNull public Alarm createAlarm(@NotNull software.constructs.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.
    • 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 MathExpression with(@NotNull MathExpressionOptions 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.
    • getExpression

      @Stability(Stable) @NotNull public String getExpression()
      The expression defining the metric.
    • getPeriod

      @Stability(Stable) @NotNull public Duration getPeriod()
      Aggregation period of this metric.
    • getUsingMetrics

      @Stability(Stable) @NotNull public Map<String,IMetric> getUsingMetrics()
      The metrics used in the expression as KeyValuePair <id, metric>.
    • getColor

      @Stability(Stable) @Nullable public String getColor()
      The hex color code, prefixed with '#' (e.g. '#00ff00'), to use when this metric is rendered on a graph. The Color class has a set of standard colors that can be used here.
    • getLabel

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

      @Stability(Stable) @Nullable public String getSearchAccount()
      Account to evaluate search expressions within.
    • getSearchRegion

      @Stability(Stable) @Nullable public String getSearchRegion()
      Region to evaluate search expressions within.
    • getWarnings

      @Stability(Deprecated) @Deprecated @Nullable public List<String> getWarnings()
      Deprecated.
      • use warningsV2
      (deprecated) Warnings generated by this math expression.

      Specified by:
      getWarnings in interface IMetric
    • getWarningsV2

      @Stability(Stable) @Nullable public Map<String,String> getWarningsV2()
      Warnings generated by this math expression.
      Specified by:
      getWarningsV2 in interface IMetric