aws-cdk-lib.aws_logs.MetricFilter

class MetricFilter (construct)

LanguageType name
.NETAmazon.CDK.AWS.Logs.MetricFilter
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awslogs#MetricFilter
Javasoftware.amazon.awscdk.services.logs.MetricFilter
Pythonaws_cdk.aws_logs.MetricFilter
TypeScript (source)aws-cdk-lib » aws_logs » MetricFilter

Implements IConstruct, IDependable, IResource

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

Example

new MetricFilter(this, 'MetricFilter', {
  logGroup,
  metricNamespace: 'MyApp',
  metricName: 'Latency',
  filterPattern: FilterPattern.exists('$.latency'),
  metricValue: '$.latency',
});

Initializer

new MetricFilter(scope: Construct, id: string, props: MetricFilterProps)

Parameters

  • scope Construct
  • id string
  • props MetricFilterProps

Construct Props

NameTypeDescription
filterPatternIFilterPatternPattern to search for log events.
logGroupILogGroupThe log group to create the filter on.
metricNamestringThe name of the metric to emit.
metricNamespacestringThe namespace of the metric to emit.
defaultValue?numberThe value to emit if the pattern does not match a particular event.
dimensions?{ [string]: string }The fields to use as dimensions for the metric.
filterName?stringThe name of the metric filter.
metricValue?stringThe value to emit for the metric.
unit?UnitThe unit to assign to the metric.

filterPattern

Type: IFilterPattern

Pattern to search for log events.


logGroup

Type: ILogGroup

The log group to create the filter on.


metricName

Type: string

The name of the metric to emit.


metricNamespace

Type: string

The namespace of the metric to emit.


defaultValue?

Type: number (optional, default: No metric emitted.)

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


dimensions?

Type: { [string]: string } (optional, default: No dimensions attached to metrics.)

The fields to use as dimensions for the metric.

One metric filter can include as many as three dimensions.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-logs-metricfilter-metrictransformation.html#cfn-logs-metricfilter-metrictransformation-dimensions


filterName?

Type: string (optional, default: Cloudformation generated name.)

The name of the metric filter.


metricValue?

Type: string (optional, default: "1")

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'.


unit?

Type: Unit (optional, default: No unit attached to metrics.)

The unit to assign to the metric.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-logs-metricfilter-metrictransformation.html#cfn-logs-metricfilter-metrictransformation-unit

Properties

NameTypeDescription
envResourceEnvironmentThe environment this resource belongs to.
nodeNodeThe tree node.
stackStackThe stack in which this resource is defined.

env

Type: ResourceEnvironment

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.


node

Type: Node

The tree node.


stack

Type: Stack

The stack in which this resource is defined.

Methods

NameDescription
applyRemovalPolicy(policy)Apply the given removal policy to this resource.
metric(props?)Return the given named metric for this Metric Filter.
toString()Returns a string representation of this construct.

applyRemovalPolicy(policy)

public applyRemovalPolicy(policy: RemovalPolicy): void

Parameters

  • policy RemovalPolicy

Apply the given removal policy to this resource.

The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.

The resource can be deleted (RemovalPolicy.DESTROY), or left in your AWS account for data recovery and cleanup later (RemovalPolicy.RETAIN).


metric(props?)

public metric(props?: MetricOptions): Metric

Parameters

  • props MetricOptions

Returns

  • Metric

Return the given named metric for this Metric Filter.


toString()

public toString(): string

Returns

  • string

Returns a string representation of this construct.