Class MathExpression

All Implemented Interfaces:

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-06-07T19:09:17.002Z") @Stability(Stable) public class MathExpression extends 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.


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

    • MathExpression

      protected MathExpression( objRef)
    • MathExpression

      protected MathExpression( initializationMode)
    • MathExpression

      @Stability(Stable) public MathExpression(@NotNull MathExpressionProps props)
      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.

      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.
      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.

      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()
      • 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