Class: AWSCDK::CloudWatch::Metric

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

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(props) ⇒ Metric

Returns a new instance of Metric.

Parameters:



21
22
23
24
25
# File 'cloud_watch/metric.rb', line 21

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

Class Method Details

.anomaly_detection_for(props) ⇒ AWSCDK::CloudWatch::MathExpression

Creates an anomaly detection metric from the provided metric.

Parameters:

Returns:



55
56
57
58
59
# File 'cloud_watch/metric.rb', line 55

def self.anomaly_detection_for(props)
  props = props.is_a?(Hash) ? ::AWSCDK::CloudWatch::AnomalyDetectionMetricOptions.new(**props.transform_keys(&:to_sym)) : props
  Jsii::Type.check_type(props, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfY2xvdWR3YXRjaC5Bbm9tYWx5RGV0ZWN0aW9uTWV0cmljT3B0aW9ucyJ9")), "props")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_cloudwatch.Metric", "anomalyDetectionFor", [props])
end

.grant_put_metric_data(grantee) ⇒ AWSCDK::IAM::Grant

Grant permissions to the given identity to write metrics.

Parameters:

Returns:



65
66
67
68
# File 'cloud_watch/metric.rb', line 65

def self.grant_put_metric_data(grantee)
  Jsii::Type.check_type(grantee, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJhd3MtY2RrLWxpYi5hd3NfaWFtLklHcmFudGFibGUifQ==")), "grantee")
  Jsii::Kernel.instance.call_static("aws-cdk-lib.aws_cloudwatch.Metric", "grantPutMetricData", [grantee])
end

.jsii_overridable_methodsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'cloud_watch/metric.rb', line 27

def self.jsii_overridable_methods
  {
    :metric_name => { kind: :property, name: "metricName", is_optional: false },
    :namespace => { kind: :property, name: "namespace", is_optional: false },
    :period => { kind: :property, name: "period", is_optional: false },
    :statistic => { kind: :property, name: "statistic", is_optional: false },
    :account => { kind: :property, name: "account", is_optional: true },
    :color => { kind: :property, name: "color", is_optional: true },
    :dimensions => { kind: :property, name: "dimensions", is_optional: true },
    :id => { kind: :property, name: "id", is_optional: true },
    :label => { kind: :property, name: "label", is_optional: true },
    :region => { kind: :property, name: "region", is_optional: true },
    :unit => { kind: :property, name: "unit", is_optional: true },
    :visible => { kind: :property, name: "visible", is_optional: true },
    :warnings => { kind: :property, name: "warnings", is_optional: true },
    :warnings_v2 => { kind: :property, name: "warningsV2", is_optional: true },
    :attach_to => { kind: :method, name: "attachTo", is_optional: false },
    :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

#accountString?

Account which this metric comes from.

Returns:

  • (String, nil)


101
102
103
# File 'cloud_watch/metric.rb', line 101

def ()
  jsii_get_property("account")
end

#attach_to(scope) ⇒ AWSCDK::CloudWatch::Metric

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 (Constructs::IConstruct)

Returns:

  • (AWSCDK::CloudWatch::Metric)


182
183
184
185
# File 'cloud_watch/metric.rb', line 182

def attach_to(scope)
  Jsii::Type.check_type(scope, JSON.parse(Base64.strict_decode64("eyJmcW4iOiJjb25zdHJ1Y3RzLklDb25zdHJ1Y3QifQ==")), "scope")
  jsii_call_method("attachTo", [scope])
end

#colorString?

The hex color code used when this metric is rendered on a graph.

Returns:

  • (String, nil)


108
109
110
# File 'cloud_watch/metric.rb', line 108

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:



196
197
198
199
200
201
202
# File 'cloud_watch/metric.rb', line 196

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

#dimensionsHash{String => Object}?

Dimensions of this metric.

Returns:

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


115
116
117
# File 'cloud_watch/metric.rb', line 115

def dimensions()
  jsii_get_property("dimensions")
end

#idString?

Unique identifier for this metric when used in dashboard widgets.

Returns:

  • (String, nil)


122
123
124
# File 'cloud_watch/metric.rb', line 122

def id()
  jsii_get_property("id")
end

#labelString?

Label for this metric when added to a Graph in a Dashboard.

Returns:

  • (String, nil)


129
130
131
# File 'cloud_watch/metric.rb', line 129

def label()
  jsii_get_property("label")
end

#metric_nameString

Name of this metric.

Returns:

  • (String)


73
74
75
# File 'cloud_watch/metric.rb', line 73

def metric_name()
  jsii_get_property("metricName")
end

#namespaceString

Namespace of this metric.

Returns:

  • (String)


80
81
82
# File 'cloud_watch/metric.rb', line 80

def namespace()
  jsii_get_property("namespace")
end

#periodAWSCDK::Duration

Period of this metric.

Returns:



87
88
89
# File 'cloud_watch/metric.rb', line 87

def period()
  jsii_get_property("period")
end

#regionString?

Region which this metric comes from.

Returns:

  • (String, nil)


136
137
138
# File 'cloud_watch/metric.rb', line 136

def region()
  jsii_get_property("region")
end

#statisticString

Statistic of this metric.

Returns:

  • (String)


94
95
96
# File 'cloud_watch/metric.rb', line 94

def statistic()
  jsii_get_property("statistic")
end

#to_metric_configAWSCDK::CloudWatch::MetricConfig

Inspect the details of the metric object.



207
208
209
# File 'cloud_watch/metric.rb', line 207

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

#to_stringString

Returns a string representation of an object.

Returns:

  • (String)


214
215
216
# File 'cloud_watch/metric.rb', line 214

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

#unitAWSCDK::CloudWatch::Unit?

Unit of the metric.

Returns:



143
144
145
# File 'cloud_watch/metric.rb', line 143

def unit()
  jsii_get_property("unit")
end

#visibleBoolean?

Whether this metric should be visible in dashboard graphs.

Returns:

  • (Boolean, nil)


150
151
152
# File 'cloud_watch/metric.rb', line 150

def visible()
  jsii_get_property("visible")
end

#warningsArray<String>?

Deprecated.
  • use warningsV2

Warnings attached to this metric.

Returns:

  • (Array<String>, nil)


158
159
160
# File 'cloud_watch/metric.rb', line 158

def warnings()
  jsii_get_property("warnings")
end

#warnings_v2Hash{String => String}?

Warnings attached to this metric.

Returns:

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


165
166
167
# File 'cloud_watch/metric.rb', line 165

def warnings_v2()
  jsii_get_property("warningsV2")
end

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

Return a copy of Metric with properties changed.

All properties except namespace and metricName can be changed.

Parameters:

Returns:

  • (AWSCDK::CloudWatch::Metric)


224
225
226
227
228
# File 'cloud_watch/metric.rb', line 224

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