put_metric_filter
¶
put_metric_filter(
log_group_name: LogGroupName,
filter_name: FilterName,
filter_pattern: FilterPattern,
metric_transformations: MetricTransformations,
*,
config_overrides: Optional[CloudWatchLogsClientConfig] = None,
apply_on_transformed_logs: Optional[ApplyOnTransformedLogs] = None,
field_selection_criteria: Optional[FieldSelectionCriteria] = None,
emit_system_field_dimensions: Optional[EmitSystemFields] = None,
) -> None
Creates or updates a metric filter and associates it with the specified log group. With metric filters, you can configure rules to extract metric data from log events ingested through PutLogEvents.
The maximum number of metric filters that can be associated with a log group is 100.
Using regular expressions in filter patterns is supported. For these filters, there is a quota of two regular expression patterns within a single filter pattern. There is also a quota of five regular expression patterns per log group. For more information about using regular expressions in filter patterns, see Filter pattern syntax for metric filters, subscription filters, filter log events, and Live Tail.
When you create a metric filter, you can also optionally assign a unit and dimensions to the metric that is created.
Metrics extracted from log events are charged as custom metrics. To prevent unexpected high charges, do not specify high-cardinality fields such as IPAddress or requestID as dimensions. Each different value found for a dimension is treated as a separate metric and accrues charges as a separate custom metric.
CloudWatch Logs might disable a metric filter if it generates 1,000 different name/value pairs for your specified dimensions within one hour.
You can also set up a billing alarm to alert you if your charges are higher than expected. For more information, see Creating a Billing Alarm to Monitor Your Estimated Amazon Web Services Charges.
Parameters:
-
log_group_name(LogGroupName) –The name of the log group.
-
filter_name(FilterName) –A name for the metric filter.
-
filter_pattern(FilterPattern) –A filter pattern for extracting metric data out of ingested log events.
-
metric_transformations(MetricTransformations) –A collection of information that defines how metric data gets emitted.
-
apply_on_transformed_logs(Optional[ApplyOnTransformedLogs], default:None) –This parameter is valid only for log groups that have an active log transformer. For more information about log transformers, see PutTransformer.
If the log group uses either a log-group level or account-level transformer, and you specify
true, the metric filter will be applied on the transformed version of the log events instead of the original ingested log events. -
field_selection_criteria(Optional[FieldSelectionCriteria], default:None) –A filter expression that specifies which log events should be processed by this metric filter based on system fields such as source account and source region. Uses selection criteria syntax with operators like
=,!=,AND,OR,IN,NOT IN. Example:@aws.region = "us-east-1"or@aws.account IN ["123456789012", "987654321098"]. Maximum length: 2000 characters. -
emit_system_field_dimensions(Optional[EmitSystemFields], default:None) –A list of system fields to emit as additional dimensions in the generated metrics. Valid values are
@aws.accountand@aws.region. These dimensions help identify the source of centralized log data and count toward the total dimension limit for metric filters.
Raises:
-
InvalidOperationException–The operation is not valid on the specified resource.
-
InvalidParameterException–A parameter is specified incorrectly.
-
LimitExceededException–You have reached the maximum number of resources that can be created.
-
OperationAbortedException–Multiple concurrent requests to update the same resource were in conflict.
-
ResourceNotFoundException–The specified resource does not exist.
-
ServiceUnavailableException–The service cannot complete the request.
-
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_cloudwatch_logs/_services/cloud_watch_logs.py
6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 | |