class MetricFilter (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.Logs.MetricFilter |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awslogs#MetricFilter |
Java | software.amazon.awscdk.services.logs.MetricFilter |
Python | aws_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
Metric
Filter Props
Construct Props
Name | Type | Description |
---|---|---|
filter | IFilter | Pattern to search for log events. |
log | ILog | The log group to create the filter on. |
metric | string | The name of the metric to emit. |
metric | string | The namespace of the metric to emit. |
default | number | The value to emit if the pattern does not match a particular event. |
dimensions? | { [string]: string } | The fields to use as dimensions for the metric. |
filter | string | The name of the metric filter. |
metric | string | The value to emit for the metric. |
unit? | Unit | The unit to assign to the metric. |
filterPattern
Type:
IFilter
Pattern to search for log events.
logGroup
Type:
ILog
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.
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.
Properties
Name | Type | Description |
---|---|---|
env | Resource | The environment this resource belongs to. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
env
Type:
Resource
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
Name | Description |
---|---|
apply | Apply the given removal policy to this resource. |
metric(props?) | Return the given named metric for this Metric Filter. |
to | Returns a string representation of this construct. |
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
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
Metric
Options
Returns
Return the given named metric for this Metric Filter.
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.