Show / Hide Table of Contents

Class Metric

A metric emitted by a service.

Inheritance
System.Object
Metric
Implements
IMetric
Namespace: Amazon.CDK.AWS.CloudWatch
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Metric : DeputyBase, IMetric
Syntax (vb)
Public Class Metric
    Inherits DeputyBase
    Implements IMetric
Remarks

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.

ExampleMetadata: infused

Examples
Function fn;


Metric minuteErrorRate = fn.MetricErrors(new MetricOptions {
    Statistic = Stats.AVERAGE,
    Period = Duration.Minutes(1),
    Label = "Lambda failure rate"
});

Synopsis

Constructors

Metric(IMetricProps)
Metric(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

Metric(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

Properties

Account

Account which this metric comes from.

Color

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

Dimensions

Dimensions of this metric.

Label

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

MetricName

Name of this metric.

Namespace

Namespace of this metric.

Period

Period of this metric.

Region

Region which this metric comes from.

Statistic

Statistic of this metric.

Unit

Unit of the metric.

Warnings

Warnings attached to this metric.

Methods

AttachTo(IConstruct)

Attach the metric object to the given construct scope.

CreateAlarm(Construct, String, ICreateAlarmOptions)

Make a new Alarm for this metric.

GrantPutMetricData(IGrantable)

Grant permissions to the given identity to write metrics.

ToMetricConfig()

Inspect the details of the metric object.

ToString()

Returns a string representation of an object.

With(IMetricOptions)

Return a copy of Metric with properties changed.

Constructors

Metric(IMetricProps)

public Metric(IMetricProps props)
Parameters
props IMetricProps

Metric(ByRefValue)

Used by jsii to construct an instance of this class from a Javascript-owned object reference

protected Metric(ByRefValue reference)
Parameters
reference Amazon.JSII.Runtime.Deputy.ByRefValue

The Javascript-owned object reference

Metric(DeputyBase.DeputyProps)

Used by jsii to construct an instance of this class from DeputyProps

protected Metric(DeputyBase.DeputyProps props)
Parameters
props Amazon.JSII.Runtime.Deputy.DeputyBase.DeputyProps

The deputy props

Properties

Account

Account which this metric comes from.

public virtual string Account { get; }
Property Value

System.String

Color

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

public virtual string Color { get; }
Property Value

System.String

Dimensions

Dimensions of this metric.

public virtual IDictionary<string, object> Dimensions { get; }
Property Value

System.Collections.Generic.IDictionary<System.String, System.Object>

Label

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

public virtual string Label { get; }
Property Value

System.String

MetricName

Name of this metric.

public virtual string MetricName { get; }
Property Value

System.String

Namespace

Namespace of this metric.

public virtual string Namespace { get; }
Property Value

System.String

Period

Period of this metric.

public virtual Duration Period { get; }
Property Value

Duration

Region

Region which this metric comes from.

public virtual string Region { get; }
Property Value

System.String

Statistic

Statistic of this metric.

public virtual string Statistic { get; }
Property Value

System.String

Unit

Unit of the metric.

public virtual Nullable<Unit> Unit { get; }
Property Value

System.Nullable<Unit>

Warnings

Warnings attached to this metric.

public virtual string[] Warnings { get; }
Property Value

System.String[]

Methods

AttachTo(IConstruct)

Attach the metric object to the given construct scope.

public virtual Metric AttachTo(IConstruct scope)
Parameters
scope Constructs.IConstruct
Returns

Metric

Remarks

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.

CreateAlarm(Construct, String, ICreateAlarmOptions)

Make a new Alarm for this metric.

public virtual Alarm CreateAlarm(Construct scope, string id, ICreateAlarmOptions props)
Parameters
scope Constructs.Construct
id System.String
props ICreateAlarmOptions
Returns

Alarm

Remarks

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

GrantPutMetricData(IGrantable)

Grant permissions to the given identity to write metrics.

public static Grant GrantPutMetricData(IGrantable grantee)
Parameters
grantee IGrantable

The IAM identity to give permissions to.

Returns

Grant

ToMetricConfig()

Inspect the details of the metric object.

public virtual IMetricConfig ToMetricConfig()
Returns

IMetricConfig

ToString()

Returns a string representation of an object.

public override string ToString()
Returns

System.String

With(IMetricOptions)

Return a copy of Metric with properties changed.

public virtual Metric With(IMetricOptions props)
Parameters
props IMetricOptions

The set of properties to change.

Returns

Metric

Remarks

All properties except namespace and metricName can be changed.

Implements

IMetric
Back to top Generated by DocFX