Class: AWSCDK::CloudWatch::MathExpression

Inherits:
Jsii::Object
  • Object
show all
Includes:
IMetric
Defined in:
cloud_watch/math_expression.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props) ⇒ MathExpression

Returns a new instance of MathExpression.



23
24
25
26
27
# File 'cloud_watch/math_expression.rb', line 23

def initialize(props)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MathExpressionProps.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NYXRoRXhwcmVzc2lvblByb3BzIn0=")), "props")
  Jsii::Object.instance_method(:initialize).bind(self).call(props)
end

Class Method Details

.jsii_overridable_methodsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'cloud_watch/math_expression.rb', line 29

def self.jsii_overridable_methods
  {
    :expression => { kind: :property, name: "expression", is_optional: false },
    :period => { kind: :property, name: "period", is_optional: false },
    :using_metrics => { kind: :property, name: "usingMetrics", is_optional: false },
    :color => { kind: :property, name: "color", is_optional: true },
    :label => { kind: :property, name: "label", is_optional: true },
    :search_account => { kind: :property, name: "searchAccount", is_optional: true },
    :search_region => { kind: :property, name: "searchRegion", is_optional: true },
    :warnings => { kind: :property, name: "warnings", is_optional: true },
    :warnings_v2 => { kind: :property, name: "warningsV2", is_optional: true },
    :create_alarm => { kind: :method, name: "createAlarm", is_optional: false },
    :to_metric_config => { kind: :method, name: "toMetricConfig", is_optional: false },
    :to_string => { kind: :method, name: "toString", is_optional: false },
    :with => { kind: :method, name: "with", is_optional: false },
  }
end

Instance Method Details

#colorString?

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.

Returns:

  • (String, nil)


71
72
73
# File 'cloud_watch/math_expression.rb', line 71

def color()
  jsii_get_property("color")
end

#create_alarm(scope, id, props) ⇒ AWSCDK::CloudWatch::Alarm

Make a new Alarm for this metric.

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

Parameters:

Returns:



120
121
122
123
124
125
126
# File 'cloud_watch/math_expression.rb', line 120

def create_alarm(scope, id, props)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLkNvbnN0cnVjdCJ9")), "scope")
  Jsii::Type.check_type(id, JSON.parse(Base64.strict_decode64("eyJwcmltaXRpdmUiOiJzdHJpbmcifQ==")), "id")
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::CreateAlarmOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5DcmVhdGVBbGFybU9wdGlvbnMifQ==")), "props")
  jsii_call_method("createAlarm", [scope, id, props])
end

#expressionString

The expression defining the metric.

Returns:

  • (String)


50
51
52
# File 'cloud_watch/math_expression.rb', line 50

def expression()
  jsii_get_property("expression")
end

#labelString?

Label for this metric when added to a Graph.

Returns:

  • (String, nil)


78
79
80
# File 'cloud_watch/math_expression.rb', line 78

def label()
  jsii_get_property("label")
end

#periodAWSCDK::Duration

Aggregation period of this metric.

Returns:



57
58
59
# File 'cloud_watch/math_expression.rb', line 57

def period()
  jsii_get_property("period")
end

#search_accountString?

Account to evaluate search expressions within.

Returns:

  • (String, nil)


85
86
87
# File 'cloud_watch/math_expression.rb', line 85

def ()
  jsii_get_property("searchAccount")
end

#search_regionString?

Region to evaluate search expressions within.

Returns:

  • (String, nil)


92
93
94
# File 'cloud_watch/math_expression.rb', line 92

def search_region()
  jsii_get_property("searchRegion")
end

#to_metric_configAWSCDK::CloudWatch::MetricConfig

Inspect the details of the metric object.



131
132
133
# File 'cloud_watch/math_expression.rb', line 131

def to_metric_config()
  jsii_call_method("toMetricConfig", [])
end

#to_stringString

Returns a string representation of an object.

Returns:

  • (String)


138
139
140
# File 'cloud_watch/math_expression.rb', line 138

def to_string()
  jsii_call_method("toString", [])
end

#using_metricsHash{String => AWSCDK::CloudWatch::IMetric}

The metrics used in the expression as KeyValuePair .

Returns:



64
65
66
# File 'cloud_watch/math_expression.rb', line 64

def using_metrics()
  jsii_get_property("usingMetrics")
end

#warningsArray<String>?

Deprecated.
  • use warningsV2

Warnings generated by this math expression.

Returns:

  • (Array<String>, nil)


100
101
102
# File 'cloud_watch/math_expression.rb', line 100

def warnings()
  jsii_get_property("warnings")
end

#warnings_v2Hash{String => String}?

Warnings generated by this math expression.

Returns:

  • (Hash{String => String}, nil)


107
108
109
# File 'cloud_watch/math_expression.rb', line 107

def warnings_v2()
  jsii_get_property("warningsV2")
end

#with(props) ⇒ AWSCDK::CloudWatch::MathExpression

Return a copy of Metric with properties changed.

All properties except namespace and metricName can be changed.

Parameters:

Returns:

  • (AWSCDK::CloudWatch::MathExpression)


148
149
150
151
152
# File 'cloud_watch/math_expression.rb', line 148

def with(props)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::MathExpressionOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5NYXRoRXhwcmVzc2lvbk9wdGlvbnMifQ==")), "props")
  jsii_call_method("with", [props])
end