# MetricProps

Properties for a metric.

Extends: MetricProps
Extends: CommonMetricOptions
Used as props by: Metric

- Source: [`aws-cloudwatch/lib/metric.ts`](https://github.com/aws/aws-cdk/blob/v2.275.0/packages/aws-cdk-lib/aws-cloudwatch/lib/metric.ts#L162)

## Example

```ts
// Create a metric
const metric = new cloudwatch.Metric({
  namespace: 'AWS/EC2',
  metricName: 'CPUUtilization',
  statistic: 'Average',
  period: Duration.hours(1), // Alarm will use the metric's period
});

// Create an anomaly detection alarm
const alarm = new cloudwatch.AnomalyDetectionAlarm(this, 'AnomalyAlarm', {
  metric: metric,
  evaluationPeriods: 1,

  // Number of standard deviations for the band (default: 2)
  stdDevs: 2,
  // Alarm outside on either side of the band, or just below or above it (default: outside)
  comparisonOperator: cloudwatch.ComparisonOperator.LESS_THAN_LOWER_OR_GREATER_THAN_UPPER_THRESHOLD,
  alarmDescription: 'Alarm when metric is outside the expected band',
});
```

## Properties

- `account`: string — Account which this metric comes from.

  **Default:** Deployment account.

- `color`: string — 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.

  **Default:** Automatic color

- `dimensionsMap`: { [key: string]: string } — Dimensions of the metric.

  **Default:** No dimensions.

- `id`: string — Unique identifier for this metric when used in dashboard widgets.

  **Default:** No ID

  The id can be used as a variable to represent this metric in math expressions.
  Valid characters are letters, numbers, and underscore. The first character
  must be a lowercase letter.

- `label`: string — Label for this metric when added to a Graph in a Dashboard.

  **Default:** No label

  You can use [dynamic labels](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html)
  to show summary information about the entire displayed time series
  in the legend. For example, if you use:

  ```
  [max: ${MAX}] MyMetric
  ```

  As the metric label, the maximum value in the visible range will
  be shown next to the time series name in the graph's legend.

- `metricName`: string (required) — Name of the metric.

- `namespace`: string (required) — Namespace of the metric.

- `period`: [Duration](/cdk/api/v2/docs/aws-cdk-lib.Duration.html) = Duration.minutes(5) — The period over which the specified statistic is applied.

- `region`: string — Region which this metric comes from.

  **Default:** Deployment region.

- `stackAccount`: string — Account of the stack this metric is attached to.

  **Default:** Deployment account.

- `stackRegion`: string — Region of the stack this metric is attached to.

  **Default:** Deployment region.

- `statistic`: string = Average — What function to use for aggregating.

  Use the `aws_cloudwatch.Stats` helper class to construct valid input strings.

  Can be one of the following:

  - "Minimum" | "min"
  - "Maximum" | "max"
  - "Average" | "avg"
  - "Sum" | "sum"
  - "SampleCount | "n"
  - "pNN.NN"
  - "tmNN.NN" | "tm(NN.NN%:NN.NN%)"
  - "iqm"
  - "wmNN.NN" | "wm(NN.NN%:NN.NN%)"
  - "tcNN.NN" | "tc(NN.NN%:NN.NN%)"
  - "tsNN.NN" | "ts(NN.NN%:NN.NN%)"

- `unit`: [Unit](/cdk/api/v2/docs/aws-cdk-lib.aws_cloudwatch.Unit.html) — Unit used to filter the metric stream.

  **Default:** All metric datums in the given metric stream

  Only refer to datums emitted to the metric stream with the given unit and
  ignore all others. Only useful when datums are being emitted to the same
  metric stream under different units.

  The default is to use all matric datums in the stream, regardless of unit,
  which is recommended in nearly all cases.

  CloudWatch does not honor this property for graphs.

- `visible`: boolean = true — Whether this metric should be visible in dashboard graphs.

  Setting this to false is useful when you want to hide raw metrics
  that are used in math expressions, and show only the expression results.
