Class: AWSCDK::CloudWatch::Metric
- Inherits:
-
Jsii::Object
- Object
- Jsii::Object
- AWSCDK::CloudWatch::Metric
- 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
-
.anomaly_detection_for(props) ⇒ AWSCDK::CloudWatch::MathExpression
Creates an anomaly detection metric from the provided metric.
-
.grant_put_metric_data(grantee) ⇒ AWSCDK::IAM::Grant
Grant permissions to the given identity to write metrics.
- .jsii_overridable_methods ⇒ Object
Instance Method Summary collapse
-
#account ⇒ String?
Account which this metric comes from.
-
#attach_to(scope) ⇒ AWSCDK::CloudWatch::Metric
Attach the metric object to the given construct scope.
-
#color ⇒ String?
The hex color code used when this metric is rendered on a graph.
-
#create_alarm(scope, id, props) ⇒ AWSCDK::CloudWatch::Alarm
Make a new Alarm for this metric.
-
#dimensions ⇒ Hash{String => Object}?
Dimensions of this metric.
-
#id ⇒ String?
Unique identifier for this metric when used in dashboard widgets.
-
#initialize(props) ⇒ Metric
constructor
A new instance of Metric.
-
#label ⇒ String?
Label for this metric when added to a Graph in a Dashboard.
-
#metric_name ⇒ String
Name of this metric.
-
#namespace ⇒ String
Namespace of this metric.
-
#period ⇒ AWSCDK::Duration
Period of this metric.
-
#region ⇒ String?
Region which this metric comes from.
-
#statistic ⇒ String
Statistic of this metric.
-
#to_metric_config ⇒ AWSCDK::CloudWatch::MetricConfig
Inspect the details of the metric object.
-
#to_string ⇒ String
Returns a string representation of an object.
-
#unit ⇒ AWSCDK::CloudWatch::Unit?
Unit of the metric.
-
#visible ⇒ Boolean?
Whether this metric should be visible in dashboard graphs.
-
#warnings ⇒ Array<String>?
deprecated
Deprecated.
- use warningsV2
-
#warnings_v2 ⇒ Hash{String => String}?
Warnings attached to this metric.
-
#with(props) ⇒ AWSCDK::CloudWatch::Metric
Return a copy of Metric
withproperties changed.
Constructor Details
#initialize(props) ⇒ Metric
Returns a new instance of Metric.
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.
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.
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_methods ⇒ Object
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
#account ⇒ String?
Account which this metric comes from.
101 102 103 |
# File 'cloud_watch/metric.rb', line 101 def account() 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.
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 |
#color ⇒ String?
The hex color code used when this metric is rendered on a graph.
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.
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 |
#dimensions ⇒ Hash{String => Object}?
Dimensions of this metric.
115 116 117 |
# File 'cloud_watch/metric.rb', line 115 def dimensions() jsii_get_property("dimensions") end |
#id ⇒ String?
Unique identifier for this metric when used in dashboard widgets.
122 123 124 |
# File 'cloud_watch/metric.rb', line 122 def id() jsii_get_property("id") end |
#label ⇒ String?
Label for this metric when added to a Graph in a Dashboard.
129 130 131 |
# File 'cloud_watch/metric.rb', line 129 def label() jsii_get_property("label") end |
#metric_name ⇒ String
Name of this metric.
73 74 75 |
# File 'cloud_watch/metric.rb', line 73 def metric_name() jsii_get_property("metricName") end |
#namespace ⇒ String
Namespace of this metric.
80 81 82 |
# File 'cloud_watch/metric.rb', line 80 def namespace() jsii_get_property("namespace") end |
#period ⇒ AWSCDK::Duration
Period of this metric.
87 88 89 |
# File 'cloud_watch/metric.rb', line 87 def period() jsii_get_property("period") end |
#region ⇒ String?
Region which this metric comes from.
136 137 138 |
# File 'cloud_watch/metric.rb', line 136 def region() jsii_get_property("region") end |
#statistic ⇒ String
Statistic of this metric.
94 95 96 |
# File 'cloud_watch/metric.rb', line 94 def statistic() jsii_get_property("statistic") end |
#to_metric_config ⇒ AWSCDK::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_string ⇒ String
Returns a string representation of an object.
214 215 216 |
# File 'cloud_watch/metric.rb', line 214 def to_string() jsii_call_method("toString", []) end |
#unit ⇒ AWSCDK::CloudWatch::Unit?
Unit of the metric.
143 144 145 |
# File 'cloud_watch/metric.rb', line 143 def unit() jsii_get_property("unit") end |
#visible ⇒ Boolean?
Whether this metric should be visible in dashboard graphs.
150 151 152 |
# File 'cloud_watch/metric.rb', line 150 def visible() jsii_get_property("visible") end |
#warnings ⇒ Array<String>?
- use warningsV2
Warnings attached to this metric.
158 159 160 |
# File 'cloud_watch/metric.rb', line 158 def warnings() jsii_get_property("warnings") end |
#warnings_v2 ⇒ Hash{String => String}?
Warnings attached to this metric.
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.
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 |