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
6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 | |