AWS Fundamentals Logo
AWS Fundamentals
L2 Construct

MetricFilter

A filter that extracts information from CloudWatch Logs and emits to CloudWatch Metrics.

Import

import { MetricFilter } from 'aws-cdk-lib/aws-logs';

Or use the module namespace:

import * as logs from 'aws-cdk-lib/aws-logs';
// logs.MetricFilter

Properties

Configuration passed to the constructor as MetricFilterProps.

logGroupRequired
ILogGroupRef

The log group to create the filter on.

9 properties inherited from MetricFilterOptions
filterPatternRequiredinherited from MetricFilterOptions
IFilterPattern

Pattern to search for log events.

metricNameRequiredinherited from MetricFilterOptions
string

The name of the metric to emit.

metricNamespaceRequiredinherited from MetricFilterOptions
string

The namespace of the metric to emit.

applyOnTransformedLogsOptionalinherited from MetricFilterOptions
boolean

Whether the metric filter is applied on the tranformed logs. This parameter is valid only for log groups that have an active log transformer. If this value is true, the metric filter is applied on the transformed version of the log events instead of the original ingested log events.

Default: - false

defaultValueOptionalinherited from MetricFilterOptions
number

The value to emit if the pattern does not match a particular event.

Default: No metric emitted.

dimensionsOptionalinherited from MetricFilterOptions
{ [key: string]: string }

The fields to use as dimensions for the metric. One metric filter can include as many as three dimensions.

Default: - No dimensions attached to metrics.

filterNameOptionalinherited from MetricFilterOptions
string

The name of the metric filter.

Default: - Cloudformation generated name.

metricValueOptionalinherited from MetricFilterOptions
string

The value to emit for the metric. Can either be a literal number (typically "1"), or the name of a field in the structure to take the value from the matched event. If you are using a field value, the field value must have been matched using the pattern. If you want to specify a field from a matched JSON structure, use '$.fieldName', and make sure the field is in the pattern (if only as '$.fieldName = *'). If you want to specify a field from a matched space-delimited structure, use '$fieldName'.

Default: "1"

unitOptionalinherited from MetricFilterOptions
Unit

The unit to assign to the metric.

Default: - No unit attached to metrics.

Learn AWS the Practical Way

Our bi-weekly newsletter teaches hands-on AWS fundamentals. No certification fluff - just practical knowledge.

Subscribe to Newsletter