Skip to content
v2.278.0

MetricFilterOptions Struct ​

Properties for a MetricFilter created from a LogGroup.

Example ​

ts
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import { aws_cloudwatch as cloudwatch } from 'aws-cdk-lib';
import { aws_logs as logs } from 'aws-cdk-lib';

declare const filterPattern: logs.IFilterPattern;
const metricFilterOptions: logs.MetricFilterOptions = {
  filterPattern: filterPattern,
  metricName: 'metricName',
  metricNamespace: 'metricNamespace',

  // the properties below are optional
  applyOnTransformedLogs: false,
  defaultValue: 123,
  dimensions: {
    dimensionsKey: 'dimensions',
  },
  filterName: 'filterName',
  metricValue: 'metricValue',
  unit: cloudwatch.Unit.SECONDS,
};
python
# The code below shows an example of how to instantiate this type.
# The values are placeholders you should change.
from aws_cdk import aws_cloudwatch as cloudwatch
from aws_cdk import aws_logs as logs

# filter_pattern: logs.IFilterPattern

metric_filter_options = logs.MetricFilterOptions(
    filter_pattern=filter_pattern,
    metric_name="metricName",
    metric_namespace="metricNamespace",

    # the properties below are optional
    apply_on_transformed_logs=False,
    default_value=123,
    dimensions={
        "dimensions_key": "dimensions"
    },
    filter_name="filterName",
    metric_value="metricValue",
    unit=cloudwatch.Unit.SECONDS
)
java
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import software.amazon.awscdk.services.cloudwatch.*;
import software.amazon.awscdk.services.logs.*;

IFilterPattern filterPattern;

MetricFilterOptions metricFilterOptions = MetricFilterOptions.builder()
        .filterPattern(filterPattern)
        .metricName("metricName")
        .metricNamespace("metricNamespace")

        // the properties below are optional
        .applyOnTransformedLogs(false)
        .defaultValue(123)
        .dimensions(Map.of(
                "dimensionsKey", "dimensions"))
        .filterName("filterName")
        .metricValue("metricValue")
        .unit(Unit.SECONDS)
        .build();
csharp
// Install: dotnet add package Amazon.CDK.Lib
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
using Amazon.CDK.AWS.CloudWatch;
using Amazon.CDK.AWS.Logs;

IFilterPattern filterPattern;

var metricFilterOptions = new MetricFilterOptions {
    FilterPattern = filterPattern,
    MetricName = "metricName",
    MetricNamespace = "metricNamespace",

    // the properties below are optional
    ApplyOnTransformedLogs = false,
    DefaultValue = 123,
    Dimensions = new Dictionary<string, string> {
        { "dimensionsKey", "dimensions" }
    },
    FilterName = "filterName",
    MetricValue = "metricValue",
    Unit = Unit.SECONDS
};
go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
// The code below shows an example of how to instantiate this type.
// The values are placeholders you should change.
import "github.com/aws/aws-cdk-go/awscdk"
import "github.com/aws/aws-cdk-go/awscdk"

var filterPattern IFilterPattern

metricFilterOptions := &MetricFilterOptions{
	FilterPattern: filterPattern,
	MetricName: jsii.String("metricName"),
	MetricNamespace: jsii.String("metricNamespace"),

	// the properties below are optional
	ApplyOnTransformedLogs: jsii.Boolean(false),
	DefaultValue: jsii.Number(123),
	Dimensions: map[string]*string{
		"dimensionsKey": jsii.String("dimensions"),
	},
	FilterName: jsii.String("filterName"),
	MetricValue: jsii.String("metricValue"),
	Unit: awscdk.Aws_cloudwatch.Unit_SECONDS,
}

Properties ​

applyOnTransformedLogsoptionalbooleanapply_on_transformed_logsoptionalboolapplyOnTransformedLogsoptionalBooleanApplyOnTransformedLogsoptionalboolApplyOnTransformedLogsoptional*bool = false #
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.

defaultValueoptionalnumberdefault_valueoptionalint | floatdefaultValueoptionalNumberDefaultValueoptionaldoubleDefaultValueoptional*float64 #
The value to emit if the pattern does not match a particular event.

Default: No metric emitted.

dimensionsoptional{ [key: string]: string }dimensionsoptionaltyping.Mapping[str, str]dimensionsoptionalMap<String, String>DimensionsoptionalIDictionary<string, string>Dimensionsoptional*map[string]*string #
The fields to use as dimensions for the metric.

Default: No dimensions attached to metrics.

One metric filter can include as many as three dimensions.

filterNameoptionalstringfilter_nameoptionalstrfilterNameoptionalStringFilterNameoptionalstringFilterNameoptional*string #
The name of the metric filter.

Default: Cloudformation generated name.

filterPatternIFilterPatternfilter_patternIFilterPatternfilterPatternIFilterPatternFilterPatternIFilterPatternFilterPatternIFilterPattern required #
Pattern to search for log events.
metricNamestringmetric_namestrmetricNameStringMetricNamestringMetricName*string required #
The name of the metric to emit.
metricNamespacestringmetric_namespacestrmetricNamespaceStringMetricNamespacestringMetricNamespace*string required #
The namespace of the metric to emit.
metricValueoptionalstringmetric_valueoptionalstrmetricValueoptionalStringMetricValueoptionalstringMetricValueoptional*string = "1" #
The value to emit for the metric.
notes

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′,andmakesurethefieldisinthepattern(ifonlyas′.fieldName = *').

If you want to specify a field from a matched space-delimited structure, use '$fieldName'.

unitoptionalUnitunitoptionalUnitunitoptionalUnitUnitoptionalUnitUnitoptionalUnit #
The unit to assign to the metric.

Default: No unit attached to metrics.